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 ChuckNorse v0.1.0
ChuckNorse.dll
Decompiled 13 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.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Microsoft.CodeAnalysis; using MyMods; using Newtonsoft.Json.Linq; using UnityEngine; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ChuckNorse")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.0.0")] [assembly: AssemblyInformationalVersion("0.1.0+0bd1a83dbfd4c46c0de3fdcfa7893c366ec1a377")] [assembly: AssemblyProduct("ChuckNorse")] [assembly: AssemblyTitle("ChuckNorse")] [assembly: AssemblyVersion("0.1.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace MyMods { public static class HallClient { private struct Pending { public string Id; public string Title; public int Order; public Action<Rect> Draw; } private static readonly List<Pending> s_pending = new List<Pending>(); private static Type s_type; private static bool s_miss; private static MethodInfo s_register; private static MethodInfo s_open; private static MethodInfo s_close; private static MethodInfo s_hosting; private static MethodInfo s_yield; private static MethodInfo s_hold; private static PropertyInfo s_ready; private static PropertyInfo s_openProp; private static Type HallType { get { if (s_type != null || s_miss) { return s_type; } s_type = Type.GetType("DFGHub.HallBoard, DFGHub"); s_miss = s_type == null; return s_type; } } public static bool Ready { get { if (s_ready == null && HallType != null) { s_ready = HallType.GetProperty("Ready", BindingFlags.Static | BindingFlags.Public); } if (s_ready == null) { return false; } object value = s_ready.GetValue(null, null); bool flag = default(bool); int num; if (value is bool) { flag = (bool)value; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } } public static bool IsOpen { get { if (s_openProp == null && HallType != null) { s_openProp = HallType.GetProperty("IsOpen", BindingFlags.Static | BindingFlags.Public); } if (s_openProp == null) { return false; } object value = s_openProp.GetValue(null, null); bool flag = default(bool); int num; if (value is bool) { flag = (bool)value; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } } public static void Bind(string id, string title, int order, Action<Rect> draw) { if (string.IsNullOrEmpty(id) || draw == null) { return; } for (int num = s_pending.Count - 1; num >= 0; num--) { if (string.Equals(s_pending[num].Id, id, StringComparison.OrdinalIgnoreCase)) { s_pending.RemoveAt(num); } } s_pending.Add(new Pending { Id = id, Title = title, Order = order, Draw = draw }); Flush(); } public static void Flush() { if (s_pending.Count != 0 && Ready) { for (int i = 0; i < s_pending.Count; i++) { Pending pending = s_pending[i]; TryRegister(pending.Id, pending.Title, pending.Order, pending.Draw); } s_pending.Clear(); } } public static bool TryOpen(string tabId) { if (!Ready) { return false; } if (s_open == null) { s_open = HallType.GetMethod("Open", BindingFlags.Static | BindingFlags.Public); } if (s_open == null) { return false; } try { object obj = s_open.Invoke(null, new object[1] { tabId }); bool flag = default(bool); int num; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } catch (Exception) { return false; } } public static void Close() { if (HallType == null) { return; } if (s_close == null) { s_close = HallType.GetMethod("Close", BindingFlags.Static | BindingFlags.Public); } try { s_close?.Invoke(null, null); } catch (Exception) { } } public static bool IsHosting(string id) { if (HallType == null || string.IsNullOrEmpty(id)) { return false; } if (s_hosting == null) { s_hosting = HallType.GetMethod("IsHosting", BindingFlags.Static | BindingFlags.Public); } if (s_hosting == null) { return false; } try { object obj = s_hosting.Invoke(null, new object[1] { id }); bool flag = default(bool); int num; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } catch (Exception) { return false; } } public static void SetYield(bool yieldScreen) { if (HallType == null) { return; } if (s_yield == null) { s_yield = HallType.GetMethod("SetYield", BindingFlags.Static | BindingFlags.Public); } try { s_yield?.Invoke(null, new object[1] { yieldScreen }); } catch (Exception) { } } public static void HoldEscape() { if (HallType == null) { return; } if (s_hold == null) { s_hold = HallType.GetMethod("HoldEscape", BindingFlags.Static | BindingFlags.Public); } try { s_hold?.Invoke(null, null); } catch (Exception) { } } private static void TryRegister(string id, string title, int order, Action<Rect> draw) { if (s_register == null) { s_register = HallType.GetMethod("Register", BindingFlags.Static | BindingFlags.Public); } s_register?.Invoke(null, new object[4] { id, title, order, draw }); } } } namespace ChuckNorse { public class ChuckAnimator : MonoBehaviour { private const float FadeSeconds = 0.2f; private readonly Dictionary<string, Transform> m_bones = new Dictionary<string, Transform>(); private Pose m_current; private Pose m_previous; private float m_time; private float m_previousTime; private float m_fade = 1f; private bool m_loop = true; private float m_speed = 1f; public string Current { get { if (m_current == null) { return null; } return m_current.Name; } } public bool Busy { get { if (m_current != null && !m_loop) { return m_time < m_current.Length; } return false; } } public void Bind(Transform armature) { m_bones.Clear(); foreach (Pose value in ChuckGlb.Poses.Values) { for (int i = 0; i < value.Tracks.Length; i++) { string path = value.Tracks[i].Path; if (!m_bones.ContainsKey(path)) { m_bones[path] = armature.Find(path); } } } } public void Play(string clip, bool loop, float speed = 1f, bool restart = false) { Pose pose = ChuckGlb.Get(clip); if (pose != null) { if (pose == m_current && !restart) { m_loop = loop; m_speed = speed; return; } m_previous = m_current; m_previousTime = m_time; m_current = pose; m_time = 0f; m_fade = ((m_previous == null) ? 1f : 0f); m_loop = loop; m_speed = speed; } } private void LateUpdate() { if (m_current != null) { float deltaTime = Time.deltaTime; m_time = Advance(m_time, deltaTime * m_speed, m_current.Length, m_loop); if (m_fade < 1f) { m_fade = Mathf.Min(1f, m_fade + deltaTime / 0.2f); } if (m_previous != null && m_fade < 1f) { m_previousTime = Advance(m_previousTime, deltaTime, m_previous.Length, loop: true); Track(m_previous, m_previousTime, 1f); Track(m_current, m_time, m_fade); } else { Track(m_current, m_time, 1f); } } } private void Track(Pose pose, float time, float weight) { //IL_005a: 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_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0085: 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_007b: 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_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) Pose.Track[] tracks = pose.Tracks; foreach (Pose.Track track in tracks) { if (m_bones.TryGetValue(track.Path, out var value) && !((Object)(object)value == (Object)null)) { if (track.SampleRotation(time, out var value2)) { value.localRotation = ((weight >= 1f) ? value2 : Quaternion.Slerp(value.localRotation, value2, weight)); } if (track.SamplePosition(time, out var value3)) { value.localPosition = ((weight >= 1f) ? value3 : Vector3.Lerp(value.localPosition, value3, weight)); } if (track.SampleScale(time, out var value4)) { value.localScale = ((weight >= 1f) ? value4 : Vector3.Lerp(value.localScale, value4, weight)); } } } } private static float Advance(float time, float dt, float length, bool loop) { if (length <= 0.0001f) { return 0f; } time += dt; if (time < length) { return time; } if (!loop) { return length; } return time % length; } } public static class ChuckBoard { private const string CoinName = "$item_coins"; private static readonly Color ColCard = new Color(0.09f, 0.11f, 0.16f, 0.96f); private static readonly Color ColLine = new Color(0.22f, 0.28f, 0.38f, 0.85f); private static readonly Color ColGold = new Color(1f, 0.84f, 0.38f, 1f); private static readonly Color ColWhite = new Color(0.92f, 0.95f, 0.98f, 1f); private static readonly Color ColMuted = new Color(0.6f, 0.66f, 0.75f, 1f); private static readonly Color ColCyan = new Color(0.4f, 0.8f, 1f, 1f); private static readonly Color ColGreen = new Color(0.38f, 0.88f, 0.44f, 1f); private static readonly Dictionary<string, GUIStyle> s_styles = new Dictionary<string, GUIStyle>(); private static Texture2D s_white; private static Vector2 s_scroll; private static string s_note = ""; public static void Draw(Rect area) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: 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_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: 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_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) EnsureTexture(); Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { GUI.Label(area, "No viking is standing here.", Style(13, bold: false, (TextAnchor)0, ColMuted, wrap: false)); return; } ChuckStats stats = ChuckStats.For(localPlayer); bool num = ((Rect)(ref area)).width >= 760f; float num2 = 210f; float num3 = 64f; float num4 = 40f + (float)ChuckStats.All.Length * (num3 + 6f); float num5 = (num ? Mathf.Max(num2, num4) : (num2 + 10f + num4)); Rect val = default(Rect); ((Rect)(ref val))..ctor(0f, 0f, ((Rect)(ref area)).width - 18f, num5); s_scroll = GUI.BeginScrollView(area, s_scroll, val); Rect r = (num ? new Rect(0f, 0f, ((Rect)(ref val)).width * 0.42f, num2) : new Rect(0f, 0f, ((Rect)(ref val)).width, num2)); DrawStatus(r, localPlayer, stats); DrawUpgrades(num ? new Rect(((Rect)(ref r)).xMax + 10f, 0f, ((Rect)(ref val)).width - ((Rect)(ref r)).width - 10f, num4) : new Rect(0f, ((Rect)(ref r)).yMax + 10f, ((Rect)(ref val)).width, num4), localPlayer, stats, num3); GUI.EndScrollView(); } private static void DrawStatus(Rect r, Player player, ChuckStats stats) { //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_0006: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: 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_011e: 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_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) Box(r, ColCard, ColLine); float num = ((Rect)(ref r)).x + 12f; float num2 = ((Rect)(ref r)).width - 24f; float num3 = ((Rect)(ref r)).y + 8f; GUI.Label(new Rect(num, num3, num2, 22f), "Chuck Norse, Tenth Realm Ranger", Style(15, bold: true, (TextAnchor)3, ColGold, wrap: false)); num3 += 24f; ChuckBody chuckBody = ChuckBody.FindFor(player.GetPlayerID()); string text; Color color; if ((Object)(object)chuckBody != (Object)null) { Character character = chuckBody.Character; text = $"On the field: {ChuckNorsePlugin.FormatSpan(TimeSpan.FromSeconds(chuckBody.SecondsLeft))} left, health {character.GetHealth():0}/{character.GetMaxHealth():0}"; color = ColGreen; } else { TimeSpan cooldownLeft = stats.CooldownLeft; text = ((cooldownLeft > TimeSpan.Zero) ? ("Resting. Back in " + ChuckNorsePlugin.FormatSpan(cooldownLeft)) : "Ready. Raise the Ranger's Call to the sky."); color = ((cooldownLeft > TimeSpan.Zero) ? ColMuted : ColGreen); } GUI.Label(new Rect(num, num3, num2, 20f), text, Style(12, bold: true, (TextAnchor)3, color, wrap: false)); num3 += 26f; Line(num, ref num3, num2, "Rank", stats.Rank + " (" + stats.KillsToNextRank + " kills to the next)"); Line(num, ref num3, num2, "Kills", stats.Kills.ToString()); Line(num, ref num3, num2, "Calls answered", stats.Summons.ToString()); Line(num, ref num3, num2, "Times fallen", stats.Falls.ToString()); Line(num, ref num3, num2, "Damage dealt", stats.DamageDealt.ToString("N0")); num3 += 4f; Line(num, ref num3, num2, "Health", stats.MaxHealth.ToString("0")); Line(num, ref num3, num2, "Damage", "x" + stats.DamageMultiplier.ToString("0.00")); Line(num, ref num3, num2, "On the field / cooldown", ChuckNorsePlugin.FormatSpan(TimeSpan.FromSeconds(stats.DurationSeconds)) + " / " + ChuckNorsePlugin.FormatSpan(TimeSpan.FromSeconds(stats.CooldownSeconds))); } private static void Line(float x, ref float y, float w, string label, string value) { //IL_000f: 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_0040: 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) GUI.Label(new Rect(x, y, w * 0.5f, 16f), label, Style(11, bold: false, (TextAnchor)3, ColMuted, wrap: false)); GUI.Label(new Rect(x + w * 0.5f, y, w * 0.5f, 16f), value, Style(11, bold: true, (TextAnchor)3, ColWhite, wrap: false)); y += 16f; } private static void DrawUpgrades(Rect r, Player player, ChuckStats stats, float rowH) { //IL_003b: 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_0087: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: 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_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: 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_0243: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_02e6: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Unknown result type (might be due to invalid IL or missing references) Inventory inventory = ((Humanoid)player).GetInventory(); int num = ((inventory != null) ? inventory.CountItems("$item_coins", -1, true) : 0); GUI.Label(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width * 0.5f, 22f), "Upgrades", Style(14, bold: true, (TextAnchor)3, ColGold, wrap: false)); GUI.Label(new Rect(((Rect)(ref r)).x + ((Rect)(ref r)).width * 0.3f, ((Rect)(ref r)).y, ((Rect)(ref r)).width * 0.7f, 22f), string.IsNullOrEmpty(s_note) ? ("Coins carried: " + num) : s_note, Style(11, bold: false, (TextAnchor)5, string.IsNullOrEmpty(s_note) ? ColMuted : ColGold, wrap: false)); float num2 = ((Rect)(ref r)).y + 30f; int value = ChuckSettings.MaxUpgradeLevel.Value; Upgrade[] all = ChuckStats.All; Rect rect = default(Rect); Rect val = default(Rect); for (int i = 0; i < all.Length; i++) { Upgrade upgrade = all[i]; ((Rect)(ref rect))..ctor(((Rect)(ref r)).x, num2, ((Rect)(ref r)).width, rowH); Box(rect, ColCard, ColLine); int num3 = stats.Level(upgrade); GUI.Label(new Rect(((Rect)(ref rect)).x + 10f, ((Rect)(ref rect)).y + 6f, ((Rect)(ref rect)).width - 200f, 18f), upgrade.ToString() + " " + num3 + "/" + value, Style(13, bold: true, (TextAnchor)3, ColGold, wrap: false)); GUI.Label(new Rect(((Rect)(ref rect)).x + 10f, ((Rect)(ref rect)).y + 26f, ((Rect)(ref rect)).width - 200f, 32f), ChuckStats.Describe(upgrade), Style(11, bold: false, (TextAnchor)0, ColMuted, wrap: true)); ((Rect)(ref val))..ctor(((Rect)(ref rect)).xMax - 184f, ((Rect)(ref rect)).y + 16f, 172f, 30f); if (num3 >= value) { GUI.Label(val, "Mastered", Style(12, bold: true, (TextAnchor)4, ColCyan, wrap: false)); } else { int num4 = num3 + 1; int num5 = ChuckStats.Cost(num4); bool num6 = stats.Rank >= num4; bool flag = num >= num5; string text = ((!num6) ? ("Needs rank " + num4) : (num5 + " coins")); bool flag2 = num6 && flag; Color background = (flag2 ? new Color(0.18f, 0.45f, 0.25f, 0.95f) : new Color(0.14f, 0.16f, 0.2f, 0.7f)); if (Button(val, text, background, flag2 ? ColWhite : ColMuted) && flag2) { if (num5 > 0) { inventory.RemoveItem("$item_coins", num5, -1, true); } stats.SetLevel(upgrade, num4); s_note = upgrade.ToString() + " is now level " + num4 + ". It applies the next time Chuck is called."; } } num2 += rowH + 6f; } } private static void EnsureTexture() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_0021: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)s_white != (Object)null)) { s_white = new Texture2D(1, 1); s_white.SetPixel(0, 0, Color.white); s_white.Apply(); } } private static void Box(Rect rect, Color background, Color border) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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_008e: 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) Color color = GUI.color; GUI.color = background; GUI.DrawTexture(rect, (Texture)(object)s_white); GUI.color = border; GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width, 1f), (Texture)(object)s_white); GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).yMax - 1f, ((Rect)(ref rect)).width, 1f), (Texture)(object)s_white); GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, 1f, ((Rect)(ref rect)).height), (Texture)(object)s_white); GUI.DrawTexture(new Rect(((Rect)(ref rect)).xMax - 1f, ((Rect)(ref rect)).y, 1f, ((Rect)(ref rect)).height), (Texture)(object)s_white); GUI.color = color; } private static bool Button(Rect rect, string text, Color background, Color textColor) { //IL_0015: 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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004c: 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) bool flag = ((Rect)(ref rect)).Contains((Event.current != null) ? Event.current.mousePosition : Vector2.zero); Box(rect, flag ? (background * 1.15f) : background, flag ? ColGold : ColLine); GUI.Label(rect, text, Style(12, bold: true, (TextAnchor)4, textColor, wrap: false)); return GUI.Button(rect, GUIContent.none, GUIStyle.none); } private static GUIStyle Style(int size, bool bold, TextAnchor anchor, Color color, bool wrap) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected I4, but got Unknown //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: 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_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Expected O, but got Unknown //IL_00da: 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_00f2: Unknown result type (might be due to invalid IL or missing references) string key = size + ":" + (bold ? 1 : 0) + ":" + (int)anchor + ":" + (wrap ? 1 : 0) + ":" + color.r.ToString("F2") + color.g.ToString("F2"); if (!s_styles.TryGetValue(key, out var value)) { value = new GUIStyle(GUI.skin.label) { fontSize = size, fontStyle = (FontStyle)(bold ? 1 : 0), alignment = anchor, clipping = (TextClipping)1, wordWrap = wrap }; value.normal.textColor = color; value.hover.textColor = color; value.active.textColor = color; s_styles[key] = value; } return value; } } public class ChuckBody : MonoBehaviour { public const string KeyOwner = "chucknorse_owner"; public const string KeyArrive = "chucknorse_arrive"; public const string KeyExpire = "chucknorse_expire"; public const string KeyDamage = "chucknorse_dmg"; public const string KeySpeed = "chucknorse_spd"; public const string KeyBow = "chucknorse_bow"; public const string KeyTalk = "chucknorse_talk"; public const string KeyLine = "chucknorse_line"; public const string KeySaid = "chucknorse_said"; private const float BowSeconds = 2.6f; private const float StrikeLeadSeconds = 0.35f; public static readonly List<ChuckBody> Live = new List<ChuckBody>(); private static readonly MethodInfo s_unSummon = AccessTools.Method(typeof(Tameable), "UnSummon", (Type[])null, (Type[])null); private static readonly FieldRef<VisEquipment, GameObject> s_rightItem = AccessTools.FieldRefAccess<VisEquipment, GameObject>("m_rightItemInstance"); private static readonly FieldRef<VisEquipment, int> s_rightHash = AccessTools.FieldRefAccess<VisEquipment, int>("m_rightItem"); private Character m_character; private ZNetView m_nview; private Tameable m_tameable; private Transform m_model; private ChuckAnimator m_anim; private float m_modelScale = 1f; private float m_walkBase; private float m_runBase; private float m_swimBase; private bool m_statsRead; private bool m_landed; private bool m_wasAttacking; private float m_bowStarted = -1f; private bool m_struck; private bool m_dismissed; private bool m_warnedUntamed; private readonly HashSet<int> m_scaledWeapons = new HashSet<int>(); private bool m_weaponMissing; private int m_heardLine = int.MinValue; private float m_idleSince = -1f; private float m_nextFidget; private float m_fidgetUntil; private static readonly string[] Attacks = new string[3] { "front_kick_01", "front_kick_02", "box_01" }; private static readonly string[] IdleVariants = new string[3] { "look_around", "scratch", "press-up" }; public Character Character => m_character; public long Owner { get { if (!((Object)(object)m_nview != (Object)null) || !m_nview.IsValid()) { return 0L; } return m_nview.GetZDO().GetLong("chucknorse_owner", 0L); } } public float DamageMultiplier { get { if (!((Object)(object)m_nview != (Object)null) || !m_nview.IsValid()) { return 1f; } return m_nview.GetZDO().GetFloat("chucknorse_dmg", 1f); } } public float SecondsLeft { get { if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid() || (Object)(object)ZNet.instance == (Object)null) { return 0f; } return Mathf.Max(0f, m_nview.GetZDO().GetFloat("chucknorse_expire", 0f) - (float)ZNet.instance.GetTimeSeconds()); } } public float TimeFraction { get { if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid()) { return 0f; } ZDO zDO = m_nview.GetZDO(); float num = zDO.GetFloat("chucknorse_expire", 0f) - zDO.GetFloat("chucknorse_arrive", 0f); if (num < 1f) { return 0f; } return Mathf.Clamp01(SecondsLeft / num); } } public ChuckMood Mood { get { //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) if ((Object)(object)m_character == (Object)null) { return ChuckMood.Idle; } if (m_character.IsDead()) { return ChuckMood.Fallen; } if ((Object)(object)m_nview != (Object)null && m_nview.IsValid() && m_nview.GetZDO().GetBool("chucknorse_bow", false)) { return ChuckMood.Leaving; } if (!m_landed) { return ChuckMood.Arrival; } if (m_character.InAttack()) { return ChuckMood.Combat; } BaseAI baseAI = m_character.GetBaseAI(); if ((Object)(object)baseAI != (Object)null) { Character targetCreature = baseAI.GetTargetCreature(); if (baseAI.IsAlerted() || ((Object)(object)targetCreature != (Object)null && !targetCreature.IsPlayer())) { return ChuckMood.Hunt; } } if (m_character.IsSwimming()) { return ChuckMood.Swim; } Vector3 velocity = m_character.GetVelocity(); velocity.y = 0f; float magnitude = ((Vector3)(ref velocity)).magnitude; if (magnitude > 3.2f) { return ChuckMood.Run; } if (magnitude > 0.35f) { return ChuckMood.Walk; } return ChuckMood.Idle; } } public static ChuckBody FindFor(long playerId) { for (int num = Live.Count - 1; num >= 0; num--) { ChuckBody chuckBody = Live[num]; if ((Object)(object)chuckBody == (Object)null) { Live.RemoveAt(num); } else if (chuckBody.Owner == playerId && (Object)(object)chuckBody.m_character != (Object)null && !chuckBody.m_character.IsDead()) { return chuckBody; } } return null; } private void Awake() { m_character = ((Component)this).GetComponent<Character>(); m_nview = ((Component)this).GetComponent<ZNetView>(); m_tameable = ((Component)this).GetComponent<Tameable>(); if ((Object)(object)m_character != (Object)null) { m_walkBase = m_character.m_walkSpeed; m_runBase = m_character.m_runSpeed; m_swimBase = m_character.m_swimSpeed; } AttachModel(); } private void OnEnable() { if (!Live.Contains(this)) { Live.Add(this); } } private void OnDisable() { Live.Remove(this); } private void Start() { if (!((Object)(object)m_nview == (Object)null) && m_nview.IsValid()) { ZDO zDO = m_nview.GetZDO(); if (m_nview.IsOwner() && zDO.GetFloat("chucknorse_expire", 0f) <= 0f) { ApplySummonerStats(zDO); } } } private void ApplySummonerStats(ZDO zdo) { //IL_00f1: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; ChuckStats chuckStats = ChuckStats.For(localPlayer); if (chuckStats != null) { float num = (float)ZNet.instance.GetTimeSeconds(); zdo.Set("chucknorse_owner", localPlayer.GetPlayerID()); zdo.Set("chucknorse_arrive", num); zdo.Set("chucknorse_expire", num + chuckStats.DurationSeconds); zdo.Set("chucknorse_dmg", chuckStats.DamageMultiplier); zdo.Set("chucknorse_spd", chuckStats.SpeedMultiplier); m_character.SetMaxHealth(chuckStats.MaxHealth); m_character.SetHealth(chuckStats.MaxHealth); m_character.SetTamed(true); BaseAI baseAI = m_character.GetBaseAI(); MonsterAI val = (MonsterAI)(object)((baseAI is MonsterAI) ? baseAI : null); if (val != null) { val.SetFollowTarget(((Component)localPlayer).gameObject); } ManualLogSource log = ChuckNorsePlugin.Log; object[] obj = new object[4] { localPlayer.GetPlayerName(), m_character.IsTamed(), m_character.GetFaction(), null }; BaseAI baseAI2 = m_character.GetBaseAI(); MonsterAI val2 = (MonsterAI)(object)((baseAI2 is MonsterAI) ? baseAI2 : null); obj[3] = val2 != null && (Object)(object)val2.GetFollowTarget() == (Object)(object)((Component)localPlayer).gameObject; log.LogInfo((object)string.Format("Chuck Norse: answered {0}'s call. tamed={1}, faction={2}, following={3}.", obj)); if (ChuckSettings.Debug.Value) { ChuckNorsePlugin.Log.LogInfo((object)$"Chuck Norse: summoned for {localPlayer.GetPlayerName()}: hp {chuckStats.MaxHealth:0}, damage x{chuckStats.DamageMultiplier:0.00}, speed x{chuckStats.SpeedMultiplier:0.00}, {chuckStats.DurationSeconds:0}s on the field."); } } } private void AttachModel() { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_008c: 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_00ac: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ChuckGlb.Template == (Object)null) { return; } GameObject val = Object.Instantiate<GameObject>(ChuckGlb.Template, ((Component)this).transform, false); ((Object)val).name = "ChuckModel"; ((Object)val).hideFlags = (HideFlags)0; m_model = val.transform; float num = Mathf.Max(0.01f, ((Component)this).transform.lossyScale.y); m_modelScale = ChuckSettings.Height.Value / Mathf.Max(0.01f, ChuckGlb.RawHeight); m_model.localScale = Vector3.one * (m_modelScale / num); m_model.localPosition = Vector3.zero; m_model.localRotation = Quaternion.identity; val.SetActive(true); Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true); foreach (Renderer val2 in componentsInChildren) { if (!((Component)val2).transform.IsChildOf(m_model)) { val2.enabled = false; } } m_anim = val.AddComponent<ChuckAnimator>(); m_anim.Bind(m_model.Find("Armature")); } private void FitWeapon() { //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) VisEquipment component = ((Component)this).GetComponent<VisEquipment>(); if ((Object)(object)component == (Object)null) { return; } string value = ChuckSettings.Weapon.Value; if (string.IsNullOrWhiteSpace(value)) { return; } int stableHashCode = StringExtensionMethods.GetStableHashCode(value.Trim()); if (s_rightHash.Invoke(component) != stableHashCode) { if ((Object)(object)ObjectDB.instance == (Object)null || (Object)(object)ObjectDB.instance.GetItemPrefab(value.Trim()) == (Object)null) { if (!m_weaponMissing) { m_weaponMissing = true; ChuckNorsePlugin.Log.LogWarning((object)("Chuck Norse: weapon '" + value + "' was not found. He keeps the troll's log.")); } return; } if ((Object)(object)m_nview != (Object)null && m_nview.IsOwner()) { component.SetRightItem(stableHashCode, 1); } } GameObject val = s_rightItem.Invoke(component); if (!((Object)(object)val == (Object)null) && s_rightHash.Invoke(component) == stableHashCode && m_scaledWeapons.Add(((Object)val).GetInstanceID())) { float num = Mathf.Clamp(ChuckSettings.WeaponScale.Value, 0.15f, 3f); if (Mathf.Abs(num - 1f) > 0.001f) { Transform transform = val.transform; transform.localScale *= num; } ChuckNorsePlugin.Log.LogInfo((object)$"Chuck Norse: holding '{value.Trim()}' at scale {num:0.00}."); } } private void Update() { //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid() || (Object)(object)m_character == (Object)null || (Object)(object)m_anim == (Object)null) { return; } FitWeapon(); ZDO zDO = m_nview.GetZDO(); ReadSpeed(zDO); float now = (((Object)(object)ZNet.instance != (Object)null) ? ((float)ZNet.instance.GetTimeSeconds()) : Time.time); if (UpdateFall(zDO, now)) { return; } if (m_nview.IsOwner()) { if (!m_character.IsTamed()) { m_character.SetTamed(true); if (!m_warnedUntamed) { m_warnedUntamed = true; ChuckNorsePlugin.Log.LogWarning((object)"Chuck Norse: found untamed; re-tamed him."); } } UpdateLifetime(zDO, now); } if (!zDO.GetBool("chucknorse_bow", false) && !m_character.IsDead()) { MaybeTalk(zDO, now); } if (zDO.GetBool("chucknorse_bow", false)) { m_anim.Play("bow", loop: false); } else { if (m_character.IsDead()) { return; } bool flag = m_character.InAttack(); if (flag && !m_wasAttacking) { string text = Attacks[Random.Range(0, Attacks.Length)]; Pose pose = ChuckGlb.Get(text); float speed = ((pose != null) ? Mathf.Clamp(pose.Length / 1.2f, 1f, 2.2f) : 1.4f); m_anim.Play(text, loop: false, speed, restart: true); } m_wasAttacking = flag; if (!flag && !m_anim.Busy) { Vector3 velocity = m_character.GetVelocity(); velocity.y = 0f; float magnitude = ((Vector3)(ref velocity)).magnitude; if (m_character.IsSwimming()) { m_idleSince = -1f; m_anim.Play("swim", loop: true, (magnitude > 0.2f) ? PlaybackRate("swim", magnitude) : 0.6f); } else if (magnitude > 3.2f) { m_idleSince = -1f; m_anim.Play("run", loop: true, PlaybackRate("run", magnitude)); } else if (magnitude > 0.35f) { m_idleSince = -1f; m_anim.Play("walk", loop: true, PlaybackRate("walk", magnitude)); } else { UpdateIdle(); } } } } private void MaybeTalk(ZDO zdo, float now) { //IL_00b0: 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_012a: 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) if ((Object)(object)Chat.instance == (Object)null || ChuckLines.Count == 0) { return; } float num = Mathf.Clamp(ChuckSettings.TalkSeconds.Value, 8f, 180f); if (m_nview.IsOwner()) { float num2 = zdo.GetFloat("chucknorse_talk", 0f); if (num2 <= 0f) { zdo.Set("chucknorse_talk", now + 8f); } else if (now >= num2) { zdo.Set("chucknorse_line", ChuckLines.Next()); zdo.Set("chucknorse_said", now); zdo.Set("chucknorse_talk", now + num); } } Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && !(Vector3.Distance(((Component)this).transform.position, ((Component)localPlayer).transform.position) > 40f)) { int num3 = zdo.GetInt("chucknorse_line", -1); float num4 = zdo.GetFloat("chucknorse_said", 0f); float num5 = Mathf.Clamp(num * 0.55f, 8f, 14f); if (num3 >= 0 && num3 != m_heardLine && !(now - num4 > num5)) { m_heardLine = num3; Chat.instance.SetNpcText(((Component)this).gameObject, Vector3.up * (ChuckSettings.Height.Value + 0.55f), 40f, num5, "Chuck Norse", ChuckLines.Text(num3), false); } } } private void UpdateIdle() { float time = Time.time; if (m_idleSince < 0f) { m_idleSince = time; m_nextFidget = time + Random.Range(12f, 25f); m_fidgetUntil = 0f; } if (time < m_fidgetUntil) { return; } if (time >= m_nextFidget) { string text = IdleVariants[Random.Range(0, IdleVariants.Length)]; Pose pose = ChuckGlb.Get(text); if (pose != null) { m_anim.Play(text, loop: true, 1f, restart: true); m_fidgetUntil = time + Mathf.Max(pose.Length, 6f); } m_nextFidget = time + Random.Range(20f, 40f); } else { m_anim.Play("idle", loop: true); } } private float PlaybackRate(string clip, float speed) { Pose pose = ChuckGlb.Get(clip); float num = ((pose != null) ? (pose.Travel * m_modelScale) : 0f); if (!(num > 0.01f)) { return 1f; } return Mathf.Clamp(speed / num, 0.5f, 2.5f); } private void ReadSpeed(ZDO zdo) { if (!m_statsRead) { float num = zdo.GetFloat("chucknorse_spd", 0f); if (!(num <= 0f)) { m_character.m_walkSpeed = m_walkBase * num; m_character.m_runSpeed = m_runBase * num; m_character.m_swimSpeed = m_swimBase * num; m_statsRead = true; } } } private bool UpdateFall(ZDO zdo, float now) { //IL_00e9: 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_00b9: 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_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) if (m_landed) { return false; } float num = zdo.GetFloat("chucknorse_arrive", 0f); float value = ChuckSettings.DropSeconds.Value; float num2 = ((num > 0f) ? ((now - num) / value) : 1f); if (num <= 0f && m_nview.IsOwner()) { num2 = 0f; } if (num2 < 1f && ChuckSettings.DropHeight.Value > 0f) { float num3 = 1f - Mathf.Clamp01(num2); float num4 = ChuckSettings.DropHeight.Value * num3 * num3; m_model.localPosition = new Vector3(0f, num4 / Mathf.Max(0.01f, ((Component)this).transform.lossyScale.y), 0f); m_anim.Play("fall", loop: true); return true; } m_landed = true; m_model.localPosition = Vector3.zero; if (num > 0f && now - num < value + 2f) { EffectList landEffects = ChuckPrefabs.LandEffects; if (landEffects != null) { landEffects.Create(((Component)this).transform.position, ((Component)this).transform.rotation, (Transform)null, 1f, -1, ZDOID.None); } m_anim.Play("jump_down", loop: false, 1f, restart: true); } return false; } private void UpdateLifetime(ZDO zdo, float now) { //IL_00ab: Unknown result type (might be due to invalid IL or missing references) float num = zdo.GetFloat("chucknorse_expire", 0f); if (num <= 0f || now < num) { return; } if (!zdo.GetBool("chucknorse_bow", false)) { zdo.Set("chucknorse_bow", true); m_bowStarted = now; BaseAI baseAI = m_character.GetBaseAI(); MonsterAI val = (MonsterAI)(object)((baseAI is MonsterAI) ? baseAI : null); if (val != null) { val.SetFollowTarget((GameObject)null); } Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)2, "Chuck Norse bows out.", 0, (Sprite)null, false); } } else { if (m_bowStarted < 0f) { m_bowStarted = now; } if (!m_struck && now - m_bowStarted >= 2.6f) { m_struck = true; ChuckStrike.Broadcast(((Component)this).transform.position); } if (now - m_bowStarted >= 2.9499998f) { Dismiss(); } } } private void Dismiss() { if (!m_dismissed) { m_dismissed = true; if ((Object)(object)m_tameable != (Object)null && s_unSummon != null) { s_unSummon.Invoke(m_tameable, null); } else if ((Object)(object)ZNetScene.instance != (Object)null) { ZNetScene.instance.Destroy(((Component)this).gameObject); } } } } internal sealed class ChuckReadyCommand : ConsoleCommand { public override string Name => "chuck_ready"; public override string Help => "Chuck Norse: clear your Ranger's Call cooldown"; public override void Run(string[] args) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { Console.instance.Print("chuck_ready: no local player."); return; } ChuckStats.For(localPlayer).ReadyAtUtc = DateTime.MinValue; Console.instance.Print("Chuck Norse is ready to answer the call."); } } public static class ChuckGlb { private sealed class Node { public string Name; public int[] Children; public Vector3 Translation = Vector3.zero; public Quaternion Rotation = Quaternion.identity; public Vector3 Scale = Vector3.one; public int Mesh = -1; } private sealed class Doc { private struct Accessor { public int Count; public int Components; public int ComponentSize; public int Offset; public int Stride; } public readonly JObject Root; public readonly List<Node> Nodes = new List<Node>(); public readonly int SceneRoot; public readonly int[] SkinJoints; public readonly int BaseColorImage = 1; private readonly Bin m_bin; private readonly JArray m_accessors; private readonly JArray m_views; private readonly JArray m_images; public Doc(JObject root, Bin bin) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Expected O, but got Unknown //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Expected O, but got Unknown //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Expected O, but got Unknown //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Expected O, but got Unknown Root = root; m_bin = bin; m_accessors = (JArray)root["accessors"]; m_views = (JArray)root["bufferViews"]; m_images = (JArray)root["images"]; JArray val = (JArray)root["nodes"]; for (int i = 0; i < ((JContainer)val).Count; i++) { Nodes.Add(ReadNode((JObject)val[i])); } SceneRoot = (int)root["scenes"][(object)0][(object)"nodes"][(object)0]; JArray val2 = (JArray)root["skins"]; if (val2 != null && ((JContainer)val2).Count > 0) { JArray val3 = (JArray)val2[0][(object)"joints"]; SkinJoints = new int[((JContainer)val3).Count]; for (int j = 0; j < ((JContainer)val3).Count; j++) { SkinJoints[j] = (int)val3[j]; } } JToken val4 = ((JToken)root).SelectToken("materials[0].pbrMetallicRoughness.baseColorTexture.index"); JArray val5 = (JArray)root["textures"]; if (val4 != null && val5 != null && (int)val4 < ((JContainer)val5).Count && val5[(int)val4][(object)"source"] != null) { BaseColorImage = (int)val5[(int)val4][(object)"source"]; } } public Mesh ReadMesh(int boneCount) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //IL_00df: 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_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Expected O, but got Unknown JObject val = (JObject)Root["meshes"][(object)0][(object)"primitives"][(object)0]; JObject val2 = (JObject)val["attributes"]; Vector3[] array = ReadVec3((int)val2["POSITION"]); Vector3[] normals = ReadVec3((int)val2["NORMAL"]); Vector2[] uv = ReadVec2((int)val2["TEXCOORD_0"]); int[] array2 = ReadIndices((int)val["indices"]); BoneWeight[] boneWeights = ReadWeights((int)val2["JOINTS_0"], (int)val2["WEIGHTS_0"], boneCount); Matrix4x4[] array3 = (Matrix4x4[])(object)new Matrix4x4[boneCount]; for (int i = 0; i < array3.Length; i++) { array3[i] = Matrix4x4.identity; } Color32[] array4 = (Color32[])(object)new Color32[array.Length]; for (int j = 0; j < array4.Length; j++) { array4[j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue); } Mesh val3 = new Mesh { name = "ChuckNorse_Mesh" }; if (array.Length > 65535) { val3.indexFormat = (IndexFormat)1; } val3.vertices = array; val3.normals = normals; val3.uv = uv; val3.colors32 = array4; val3.boneWeights = boneWeights; val3.bindposes = array3; int[] array5 = new int[array2.Length * 2]; Array.Copy(array2, array5, array2.Length); for (int k = 0; k < array2.Length; k += 3) { array5[array2.Length + k] = array2[k]; array5[array2.Length + k + 1] = array2[k + 2]; array5[array2.Length + k + 2] = array2[k + 1]; } val3.triangles = array5; val3.RecalculateTangents(); val3.RecalculateBounds(); return val3; } public float[] ReadFloats(int accessor) { Accessor accessor2 = GetAccessor(accessor); int num = accessor2.Count * accessor2.Components; float[] array = new float[num]; for (int i = 0; i < num; i++) { int num2 = i / accessor2.Components; int num3 = i % accessor2.Components; array[i] = m_bin.Float(accessor2.Offset + num2 * accessor2.Stride + num3 * 4); } return array; } public Texture2D ReadImage(int imageIndex, bool linear) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Expected O, but got Unknown if (m_images == null || imageIndex < 0 || imageIndex >= ((JContainer)m_images).Count) { return null; } JObject val = (JObject)m_images[imageIndex]; if (val["bufferView"] == null) { return null; } JObject val2 = (JObject)m_views[(int)val["bufferView"]]; int offset = ((val2["byteOffset"] != null) ? ((int)val2["byteOffset"]) : 0); byte[] array = m_bin.Slice(offset, (int)val2["byteLength"]); Texture2D val3 = new Texture2D(2, 2, (TextureFormat)4, true, linear); if (!ImageConversion.LoadImage(val3, array)) { ChuckNorsePlugin.Log.LogWarning((object)("Chuck Norse: failed to decode image " + (object)val["name"])); Object.Destroy((Object)(object)val3); return null; } ((Object)val3).name = ((string)val["name"]) ?? "chuck_tex"; ((Texture)val3).wrapMode = (TextureWrapMode)1; ((Texture)val3).anisoLevel = 4; return val3; } private Vector3[] ReadVec3(int accessor) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) Accessor accessor2 = GetAccessor(accessor); Vector3[] array = (Vector3[])(object)new Vector3[accessor2.Count]; for (int i = 0; i < accessor2.Count; i++) { int num = accessor2.Offset + i * accessor2.Stride; array[i] = new Vector3(m_bin.Float(num), m_bin.Float(num + 4), 0f - m_bin.Float(num + 8)); } return array; } private Vector2[] ReadVec2(int accessor) { //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) Accessor accessor2 = GetAccessor(accessor); Vector2[] array = (Vector2[])(object)new Vector2[accessor2.Count]; for (int i = 0; i < accessor2.Count; i++) { int num = accessor2.Offset + i * accessor2.Stride; array[i] = new Vector2(m_bin.Float(num), 1f - m_bin.Float(num + 4)); } return array; } private int[] ReadIndices(int accessor) { Accessor accessor2 = GetAccessor(accessor); int[] array = new int[accessor2.Count]; int componentSize = accessor2.ComponentSize; for (int i = 0; i < accessor2.Count; i++) { int offset = accessor2.Offset + i * componentSize; array[i] = componentSize switch { 2 => m_bin.UInt16(offset), 4 => (int)m_bin.UInt32(offset), _ => m_bin.Byte(offset), }; } return array; } private BoneWeight[] ReadWeights(int jointsAccessor, int weightsAccessor, int boneCount) { //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) Accessor accessor = GetAccessor(jointsAccessor); Accessor accessor2 = GetAccessor(weightsAccessor); BoneWeight[] array = (BoneWeight[])(object)new BoneWeight[accessor.Count]; for (int i = 0; i < accessor.Count; i++) { int elementOffset = accessor.Offset + i * accessor.Stride; int num = accessor2.Offset + i * accessor2.Stride; float num2 = m_bin.Float(num); float num3 = m_bin.Float(num + 4); float num4 = m_bin.Float(num + 8); float num5 = m_bin.Float(num + 12); float num6 = num2 + num3 + num4 + num5; if (num6 > 0.0001f) { num2 /= num6; num3 /= num6; num4 /= num6; num5 /= num6; } else { num2 = 1f; } int num7 = i; BoneWeight val = default(BoneWeight); ((BoneWeight)(ref val)).boneIndex0 = Joint(accessor, elementOffset, 0, boneCount); ((BoneWeight)(ref val)).weight0 = num2; ((BoneWeight)(ref val)).boneIndex1 = Joint(accessor, elementOffset, 1, boneCount); ((BoneWeight)(ref val)).weight1 = num3; ((BoneWeight)(ref val)).boneIndex2 = Joint(accessor, elementOffset, 2, boneCount); ((BoneWeight)(ref val)).weight2 = num4; ((BoneWeight)(ref val)).boneIndex3 = Joint(accessor, elementOffset, 3, boneCount); ((BoneWeight)(ref val)).weight3 = num5; array[num7] = val; } return array; } private int Joint(Accessor acc, int elementOffset, int component, int boneCount) { int offset = elementOffset + component * acc.ComponentSize; int num = ((acc.ComponentSize == 1) ? m_bin.Byte(offset) : ((acc.ComponentSize == 2) ? m_bin.UInt16(offset) : ((int)m_bin.UInt32(offset)))); if (num >= 0 && num < boneCount) { return num; } return 0; } private Accessor GetAccessor(int index) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown JObject val = (JObject)m_accessors[index]; JObject val2 = (JObject)m_views[(int)val["bufferView"]]; int num = (int)val["componentType"]; int num2 = (string)val["type"] switch { "VEC2" => 2, "VEC3" => 3, "VEC4" => 4, "MAT4" => 16, _ => 1, }; int num3; switch (num) { default: num3 = 1; break; case 5122: case 5123: num3 = 2; break; case 5125: case 5126: num3 = 4; break; } int num4 = num3; int num5 = ((val2["byteOffset"] != null) ? ((int)val2["byteOffset"]) : 0); int num6 = ((val["byteOffset"] != null) ? ((int)val["byteOffset"]) : 0); int stride = ((val2["byteStride"] != null) ? ((int)val2["byteStride"]) : (num4 * num2)); return new Accessor { Count = (int)val["count"], Components = num2, ComponentSize = num4, Offset = num5 + num6, Stride = stride }; } private static Node ReadNode(JObject n) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown //IL_0086: 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_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Expected O, but got Unknown //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Expected O, but got Unknown //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: 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_015e: Expected O, but got Unknown Node node = new Node { Name = (string)n["name"] }; if (n["mesh"] != null) { node.Mesh = (int)n["mesh"]; } if (n["translation"] != null) { JArray val = (JArray)n["translation"]; node.Translation = new Vector3((float)val[0], (float)val[1], 0f - (float)val[2]); } if (n["rotation"] != null) { JArray val2 = (JArray)n["rotation"]; node.Rotation = new Quaternion((float)val2[0], (float)val2[1], 0f - (float)val2[2], 0f - (float)val2[3]); } if (n["scale"] != null) { JArray val3 = (JArray)n["scale"]; node.Scale = new Vector3((float)val3[0], (float)val3[1], (float)val3[2]); } if (n["children"] != null) { JArray val4 = (JArray)n["children"]; node.Children = new int[((JContainer)val4).Count]; for (int i = 0; i < ((JContainer)val4).Count; i++) { node.Children[i] = (int)val4[i]; } } return node; } } private sealed class Bin { private readonly byte[] m_file; private readonly int m_start; public Bin(byte[] file, int start, int length) { m_file = file; m_start = start; } public float Float(int offset) { return BitConverter.ToSingle(m_file, m_start + offset); } public int Byte(int offset) { return m_file[m_start + offset]; } public int UInt16(int offset) { return BitConverter.ToUInt16(m_file, m_start + offset); } public uint UInt32(int offset) { return BitConverter.ToUInt32(m_file, m_start + offset); } public byte[] Slice(int offset, int length) { byte[] array = new byte[length]; Buffer.BlockCopy(m_file, m_start + offset, array, 0, length); return array; } } private const uint GlbMagic = 1179937895u; private const int FloatType = 5126; private static readonly string[] RootMotionBones = new string[2] { "Hips", "pelvis" }; public static readonly Dictionary<string, Pose> Poses = new Dictionary<string, Pose>(StringComparer.OrdinalIgnoreCase); public static GameObject Template { get; private set; } public static float RawHeight { get; private set; } public static bool Load(string path, Material sourceMaterial, Transform holder) { if ((Object)(object)Template != (Object)null) { return true; } try { Template = Build(path, sourceMaterial); Template.SetActive(false); ((Object)Template).hideFlags = (HideFlags)61; if ((Object)(object)holder != (Object)null) { Template.transform.SetParent(holder, false); } return true; } catch (Exception ex) { ChuckNorsePlugin.Log.LogError((object)("Chuck Norse: failed to build the model from " + Path.GetFileName(path) + ": " + ex)); Template = null; return false; } } public static Pose Get(string name) { if (name == null || !Poses.TryGetValue(name, out var value)) { return null; } return value; } private static GameObject Build(string path, Material sourceMaterial) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Expected O, but got Unknown //IL_00b5: 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_00e5: Expected O, but got Unknown //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0172: 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_010f: Expected O, but got Unknown byte[] array = File.ReadAllBytes(path); if (array.Length < 20 || BitConverter.ToUInt32(array, 0) != 1179937895) { throw new InvalidDataException("Not a GLB file: " + path); } int num = BitConverter.ToInt32(array, 12); string text = Encoding.UTF8.GetString(array, 20, num); int num2 = 20 + num; int length = BitConverter.ToInt32(array, num2); int start = num2 + 8; JObject obj = JObject.Parse(text); Doc doc = new Doc(obj, new Bin(array, start, length)); GameObject val = new GameObject("ChuckNorse_Model"); Dictionary<int, Transform> transforms; Dictionary<int, string> paths; GameObject obj2 = BuildHierarchy(doc, out transforms, out paths); ((Object)obj2).name = "Armature"; obj2.transform.SetParent(val.transform, false); obj2.transform.localRotation = Quaternion.Euler(0f, 180f, 0f); AttachMesh(material: CreateMaterial(doc, sourceMaterial), doc: doc, transforms: transforms); JArray val2 = (JArray)obj["animations"]; Poses.Clear(); if (val2 != null) { for (int i = 0; i < ((JContainer)val2).Count; i++) { Pose pose = BuildPose(doc, paths, (JObject)val2[i]); if (pose != null) { Poses[pose.Name] = pose; } } } SkinnedMeshRenderer componentInChildren = val.GetComponentInChildren<SkinnedMeshRenderer>(); float rawHeight; if (!((Object)(object)componentInChildren != (Object)null) || !((Object)(object)componentInChildren.sharedMesh != (Object)null)) { rawHeight = 1f; } else { Bounds bounds = componentInChildren.sharedMesh.bounds; rawHeight = ((Bounds)(ref bounds)).size.y; } RawHeight = rawHeight; ChuckNorsePlugin.Log.LogInfo((object)string.Format("Chuck Norse: built model from {0} ({1:0.00} m in the file), {2} clips: {3}.", Path.GetFileName(path), RawHeight, Poses.Count, string.Join(", ", Poses.Keys))); return val; } private static GameObject BuildHierarchy(Doc doc, out Dictionary<int, Transform> transforms, out Dictionary<int, string> paths) { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_0064: 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_0088: Unknown result type (might be due to invalid IL or missing references) int count = doc.Nodes.Count; GameObject[] array = (GameObject[])(object)new GameObject[count]; transforms = new Dictionary<int, Transform>(count); for (int i = 0; i < count; i++) { Node node = doc.Nodes[i]; GameObject val = new GameObject(string.IsNullOrEmpty(node.Name) ? ("node" + i) : node.Name); val.transform.localPosition = node.Translation; val.transform.localRotation = node.Rotation; val.transform.localScale = node.Scale; array[i] = val; transforms[i] = val.transform; } for (int j = 0; j < count; j++) { int[] children = doc.Nodes[j].Children; if (children != null) { for (int k = 0; k < children.Length; k++) { array[children[k]].transform.SetParent(array[j].transform, false); } } } paths = new Dictionary<int, string>(); WritePaths(doc, doc.SceneRoot, "", paths); return array[doc.SceneRoot]; } private static void WritePaths(Doc doc, int index, string path, Dictionary<int, string> paths) { paths[index] = path; int[] children = doc.Nodes[index].Children; if (children == null) { return; } for (int i = 0; i < children.Length; i++) { int index2 = children[i]; string text = doc.Nodes[index2].Name; if (string.IsNullOrEmpty(text)) { text = "node" + index2; } WritePaths(doc, index2, string.IsNullOrEmpty(path) ? text : (path + "/" + text), paths); } } private static void AttachMesh(Doc doc, Dictionary<int, Transform> transforms, Material material) { //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_014a: 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_0112: 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_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) int num = -1; for (int i = 0; i < doc.Nodes.Count; i++) { if (doc.Nodes[i].Mesh >= 0) { num = i; break; } } if (num < 0 || doc.SkinJoints == null) { throw new InvalidDataException("GLB has no skinned mesh."); } int[] skinJoints = doc.SkinJoints; Transform[] array = (Transform[])(object)new Transform[skinJoints.Length]; for (int j = 0; j < skinJoints.Length; j++) { array[j] = transforms[skinJoints[j]]; } Mesh val = doc.ReadMesh(array.Length); SkinnedMeshRenderer val2 = ((Component)transforms[num]).gameObject.AddComponent<SkinnedMeshRenderer>(); val2.sharedMesh = val; val2.bones = array; val2.rootBone = ((array.Length != 0) ? array[0] : null); ((Renderer)val2).sharedMaterial = material; val2.updateWhenOffscreen = false; val2.quality = (SkinQuality)4; Matrix4x4[] array2 = (Matrix4x4[])(object)new Matrix4x4[array.Length]; Matrix4x4 localToWorldMatrix = ((Component)val2).transform.localToWorldMatrix; for (int k = 0; k < array.Length; k++) { array2[k] = (((Object)(object)array[k] == (Object)null) ? Matrix4x4.identity : (array[k].worldToLocalMatrix * localToWorldMatrix)); } val.bindposes = array2; Bounds bounds = val.bounds; ((Bounds)(ref bounds)).Expand(new Vector3(1.5f, 0.6f, 1.5f)); ((Renderer)val2).localBounds = bounds; } private static Material CreateMaterial(Doc doc, Material sourceMaterial) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown //IL_002f: 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_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) Texture2D val = doc.ReadImage(doc.BaseColorImage, linear: false); Material val2 = (((Object)(object)sourceMaterial != (Object)null) ? new Material(sourceMaterial) : new Material(Shader.Find("Custom/Creature") ?? Shader.Find("Standard"))); ((Object)val2).name = "ChuckNorse_Mat"; if ((Object)(object)val != (Object)null) { val2.mainTexture = (Texture)(object)val; SetTex(val2, "_MainTex", (Texture)(object)val); SetTex(val2, "_BaseMap", (Texture)(object)val); SetTex(val2, "_Albedo", (Texture)(object)val); val2.SetTextureScale("_MainTex", Vector2.one); val2.SetTextureOffset("_MainTex", Vector2.zero); } SetTex(val2, "_BumpMap", null); SetTex(val2, "_EmissionMap", null); if (val2.HasProperty("_EmissionColor")) { val2.SetColor("_EmissionColor", Color.black); } val2.DisableKeyword("_EMISSION"); if (val2.HasProperty("_Color")) { val2.SetColor("_Color", Color.white); } if (val2.HasProperty("_BaseColor")) { val2.SetColor("_BaseColor", Color.white); } if (val2.HasProperty("_Mode")) { val2.SetFloat("_Mode", 0f); } if (val2.HasProperty("_Cutoff")) { val2.SetFloat("_Cutoff", 0f); } val2.DisableKeyword("_ALPHATEST_ON"); val2.DisableKeyword("_ALPHABLEND_ON"); val2.DisableKeyword("_ALPHAPREMULTIPLY_ON"); val2.renderQueue = 2000; ChuckNorsePlugin.Log.LogInfo((object)string.Format("Chuck Norse: material cloned from '{0}', shader '{1}', albedo {2}.", ((Object)(object)sourceMaterial != (Object)null) ? ((Object)sourceMaterial).name : "none", ((Object)(object)val2.shader != (Object)null) ? ((Object)val2.shader).name : "none", ((Object)(object)val != (Object)null) ? (((Texture)val).width + "x" + ((Texture)val).height) : "missing")); return val2; } private static void SetTex(Material mat, string prop, Texture tex) { if (mat.HasProperty(prop)) { mat.SetTexture(prop, tex); } } private static Pose BuildPose(Doc doc, Dictionary<int, string> paths, JObject anim) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown //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_0233: 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_0350: Unknown result type (might be due to invalid IL or missing references) //IL_0355: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Unknown result type (might be due to invalid IL or missing references) string text = (string)anim["name"]; if (string.IsNullOrEmpty(text)) { return null; } Dictionary<string, Pose.Track> dictionary = new Dictionary<string, Pose.Track>(); float num = 0f; float travel = 0f; JArray val = (JArray)anim["channels"]; JArray val2 = (JArray)anim["samplers"]; for (int i = 0; i < ((JContainer)val).Count; i++) { JObject val3 = (JObject)val[i]; JObject val4 = (JObject)val2[(int)val3["sampler"]]; int key = (int)val3["target"][(object)"node"]; string text2 = (string)val3["target"][(object)"path"]; if (!paths.TryGetValue(key, out var value) || string.IsNullOrEmpty(value)) { continue; } bool flag = string.Equals((string)val4["interpolation"], "STEP", StringComparison.OrdinalIgnoreCase); float[] array = doc.ReadFloats((int)val4["input"]); float[] array2 = doc.ReadFloats((int)val4["output"]); if (array.Length != 0 && array[^1] > num) { num = array[^1]; } if (!dictionary.TryGetValue(value, out var value2)) { Pose.Track obj = new Pose.Track { Path = value }; value2 = (dictionary[value] = obj); } switch (text2) { case "rotation": { Quaternion[] array5 = (Quaternion[])(object)new Quaternion[array.Length]; for (int m = 0; m < array.Length; m++) { array5[m] = new Quaternion(array2[m * 4], array2[m * 4 + 1], 0f - array2[m * 4 + 2], 0f - array2[m * 4 + 3]); } value2.RotTimes = array; value2.Rotations = array5; value2.RotationStep = flag; break; } case "translation": { bool flag2 = IsRootMotionBone(value); Vector3[] array4 = (Vector3[])(object)new Vector3[array.Length]; for (int k = 0; k < array.Length; k++) { array4[k] = new Vector3(array2[k * 3], array2[k * 3 + 1], 0f - array2[k * 3 + 2]); } if (flag2 && array.Length > 1) { Vector3 val5 = array4[array.Length - 1] - array4[0]; val5.y = 0f; float num2 = array[^1] - array[0]; travel = ((num2 > 0.0001f) ? (((Vector3)(ref val5)).magnitude / num2) : 0f); for (int l = 1; l < array.Length; l++) { array4[l].x = array4[0].x; array4[l].z = array4[0].z; } } value2.PosTimes = array; value2.Positions = array4; value2.PositionStep = flag; break; } case "scale": { Vector3[] array3 = (Vector3[])(object)new Vector3[array.Length]; for (int j = 0; j < array.Length; j++) { array3[j] = new Vector3(array2[j * 3], array2[j * 3 + 1], array2[j * 3 + 2]); } value2.ScaleTimes = array; value2.Scales = array3; value2.ScaleStep = flag; break; } } } Pose pose = new Pose { Name = text, Length = num, Travel = travel, Tracks = new Pose.Track[dictionary.Count] }; dictionary.Values.CopyTo(pose.Tracks, 0); return pose; } private static bool IsRootMotionBone(string path) { int num = path.LastIndexOf('/'); string value = ((num >= 0) ? path.Substring(num + 1) : path); return Array.IndexOf(RootMotionBones, value) >= 0; } } public sealed class Pose { public sealed class Track { public string Path; public float[] PosTimes; public Vector3[] Positions; public bool PositionStep; public float[] RotTimes; public Quaternion[] Rotations; public bool RotationStep; public float[] ScaleTimes; public Vector3[] Scales; public bool ScaleStep; public bool SamplePosition(float time, out Vector3 value) { return Sample(PosTimes, Positions, PositionStep, time, out value); } public bool SampleScale(float time, out Vector3 value) { return Sample(ScaleTimes, Scales, ScaleStep, time, out value); } public bool SampleRotation(float time, out Quaternion value) { //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_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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) value = Quaternion.identity; if (RotTimes == null || Rotations == null || RotTimes.Length == 0) { return false; } int num = Index(RotTimes, time); if (RotationStep || num + 1 >= RotTimes.Length) { value = Rotations[num]; return true; } value = Quaternion.Slerp(Rotations[num], Rotations[num + 1], Blend(RotTimes, num, time)); return true; } private static bool Sample(float[] times, Vector3[] values, bool step, float time, out Vector3 value) { //IL_0002: 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_003b: 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_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) value = default(Vector3); if (times == null || values == null || times.Length == 0) { return false; } int num = Index(times, time); if (step || num + 1 >= times.Length) { value = values[num]; return true; } value = Vector3.Lerp(values[num], values[num + 1], Blend(times, num, time)); return true; } private static int Index(float[] times, float time) { int num = 0; int num2 = times.Length - 1; if (time <= times[0]) { return 0; } if (time >= times[num2]) { return num2; } while (num2 - num > 1) { int num3 = num + num2 >> 1; if (times[num3] <= time) { num = num3; } else { num2 = num3; } } return num; } private static float Blend(float[] times, int i, float time) { float num = times[i + 1] - times[i]; if (!(num <= 1E-05f)) { return Mathf.Clamp01((time - times[i]) / num); } return 0f; } } public string Name; public float Length; public float Travel; public Track[] Tracks; } public static class ChuckHud { private static bool s_dragging; private static Vector2 s_dragOffset; private static Texture2D s_white; private static readonly Color ColHeader = new Color(0.12f, 0.16f, 0.22f, 1f); private static readonly Color ColBorder = new Color(0.74f, 0.58f, 0.28f, 1f); private static readonly Color ColCard = new Color(0.08f, 0.1f, 0.14f, 0.96f); private static readonly Color ColCardLine = new Color(0.2f, 0.26f, 0.36f, 0.85f); private static readonly Color ColBarBg = new Color(0.04f, 0.06f, 0.08f, 0.9f); private static readonly Color ColFill = new Color(0.24f, 0.7f, 0.44f, 0.9f); private static readonly Color ColLow = new Color(0.88f, 0.32f, 0.28f, 0.9f); private static readonly Color ColGold = new Color(1f, 0.84f, 0.38f, 1f); private static readonly Color ColWhite = new Color(0.92f, 0.95f, 0.98f, 1f); private static readonly Color ColDim = new Color(0.65f, 0.72f, 0.82f, 1f); private static readonly Color ColYellow = new Color(1f, 0.82f, 0.32f, 1f); private static readonly Color ColCyan = new Color(0.4f, 0.82f, 1f, 1f); private static GUIStyle s_header; private static GUIStyle s_title; private static GUIStyle s_badge; private static GUIStyle s_barText; private static GUIStyle s_desc; private static bool s_iconsTried; private static Texture2D s_portrait; private static readonly Dictionary<ChuckMood, Texture2D> s_icons = new Dictionary<ChuckMood, Texture2D>(); private static Texture2D White { get { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown //IL_0020: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)s_white == (Object)null) { s_white = new Texture2D(1, 1); s_white.SetPixel(0, 0, Color.white); s_white.Apply(); } return s_white; } } public static void Render() { //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Expected O, but got Unknown //IL_013d: 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_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_018d: 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_0208: 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_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_02e1: Unknown result type (might be due to invalid IL or missing references) //IL_0306: Unknown result type (might be due to invalid IL or missing references) //IL_0336: Unknown result type (might be due to invalid IL or missing references) //IL_03fb: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) if (ChuckSettings.HudVisible == null || !ChuckSettings.HudVisible.Value) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead()) { return; } ChuckBody chuckBody = ChuckBody.FindFor(localPlayer.GetPlayerID()); if (!((Object)(object)chuckBody == (Object)null) && !((Object)(object)chuckBody.Character == (Object)null)) { InitStyles(); EnsureIcons(); ChuckQuip chuckQuip = ChuckStatus.Describe(chuckBody.Mood); Character character = chuckBody.Character; float num = Mathf.Max(0f, character.GetHealth()); float num2 = Mathf.Max(1f, character.GetMaxHealth()); float num3 = Mathf.Max(32f, s_desc.CalcHeight(new GUIContent(chuckQuip.Description), 384f)); float num4 = 78f + num3; float num5 = 34f + num4 + 8f; float num6 = Mathf.Clamp01(ChuckSettings.HudScreenX.Value); float num7 = Mathf.Clamp01(ChuckSettings.HudScreenY.Value); float x = num6 * Mathf.Max(0f, (float)Screen.width - 420f); float y = num7 * Mathf.Max(0f, (float)Screen.height - num5); Drag(ref x, ref y, 420f, num5); DrawSolid(new Rect(x, y, 420f, num5), new Color(0.06f, 0.08f, 0.11f, 0.94f)); DrawBorder(new Rect(x, y, 420f, num5), ColBorder, 1.5f); DrawSolid(new Rect(x, y, 420f, 28f), ColHeader); float num8 = x + 10f; if ((Object)(object)s_portrait != (Object)null) { GUI.DrawTexture(new Rect(x + 6f, y + 3f, 22f, 22f), (Texture)(object)s_portrait, (ScaleMode)2, true); num8 = x + 32f; } GUI.Label(new Rect(num8, y + 3f, 420f - (num8 - x) - 8f, 22f), "CHUCK NORSE", s_header); float num9 = x + 6f; float num10 = y + 34f; float num11 = 408f; DrawSolid(new Rect(num9, num10, num11, num4), ColCard); DrawBorder(new Rect(num9, num10, num11, num4), ColCardLine, 1f); float num12 = num9 + 8f; if (s_icons.TryGetValue(chuckBody.Mood, out var value) && (Object)(object)value != (Object)null) { GUI.DrawTexture(new Rect(num9 + 6f, num10 + 3f, 22f, 22f), (Texture)(object)value, (ScaleMode)2, true); num12 = num9 + 32f; } GUI.Label(new Rect(num12, num10 + 4f, num11 * 0.58f - (num12 - num9), 20f), chuckQuip.Name, s_title); s_badge.normal.textColor = BadgeColor(chuckBody.Mood); GUI.Label(new Rect(num9 + num11 * 0.58f, num10 + 4f, num11 * 0.4f - 8f, 20f), "● " + chuckQuip.Key, s_badge); float x2 = num9 + 8f; float num13 = num11 - 16f; DrawBar(x2, num10 + 28f, num13, 16f, chuckBody.TimeFraction, chuckBody.SecondsLeft < 30f, ChuckNorsePlugin.FormatSpan(TimeSpan.FromSeconds(chuckBody.SecondsLeft)) + " left"); DrawBar(x2, num10 + 48f, num13, 16f, num / num2, num / num2 < 0.35f, $"{num:0} / {num2:0}"); GUI.Label(new Rect(num9 + 8f, num10 + 70f, num13, num3), chuckQuip.Description, s_desc); } } private static void Drag(ref float x, ref float y, float width, float height) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Invalid comparison between Unknown and I4 //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Invalid comparison between Unknown and I4 //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Invalid comparison between Unknown and I4 //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_00ad: Unknown result type (might be due to invalid IL or missing references) Event current = Event.current; if (current != null) { bool flag = Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307); Rect val = default(Rect); ((Rect)(ref val))..ctor(x, y, width, 28f); if ((int)current.type == 0 && flag && ((Rect)(ref val)).Contains(current.mousePosition)) { s_dragging = true; s_dragOffset = current.mousePosition - new Vector2(x, y); current.Use(); } else if ((int)current.type == 1) { s_dragging = false; } else if ((int)current.type == 3 && s_dragging) { Vector2 val2 = current.mousePosition - s_dragOffset; float num = Mathf.Clamp01(val2.x / Mathf.Max(1f, (float)Screen.width - width)); float num2 = Mathf.Clamp01(val2.y / Mathf.Max(1f, (float)Screen.height - height)); ChuckSettings.HudScreenX.Value = num; ChuckSettings.HudScreenY.Value = num2; x = num * Mathf.Max(0f, (float)Screen.width - width); y = num2 * Mathf.Max(0f, (float)Screen.height - height); current.Use(); } } } private static Color BadgeColor(ChuckMood mood) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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_002c: Unknown result type (might be due to invalid IL or missing references) switch (mood) { case ChuckMood.Combat: case ChuckMood.Fallen: return ColLow; case ChuckMood.Hunt: case ChuckMood.Leaving: return ColYellow; case ChuckMood.Run: case ChuckMood.Swim: return ColCyan; case ChuckMood.Arrival: case ChuckMood.Idle: return ColGold; default: return ColWhite; } } private static void DrawBar(float x, float y, float width, float height, float fill, bool low, string text) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_003c: 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) fill = Mathf.Clamp01(fill); DrawSolid(new Rect(x, y, width, height), ColBarBg); if (fill > 0f) { DrawSolid(new Rect(x, y, width * fill, height), low ? ColLow : ColFill); } DrawBorder(new Rect(x, y, width, height), ColCardLine, 1f); GUI.Label(new Rect(x + 6f, y - 1f, width - 12f, height + 2f), text, s_barText); } private static void EnsureIcons() { if (s_iconsTried) { return; } s_iconsTried = true; string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "", "icons"); s_portrait = LoadTex(Path.Combine(path, "portrait.png")); foreach (ChuckMood value in Enum.GetValues(typeof(ChuckMood))) { Texture2D val = LoadTex(Path.Combine(path, value.ToString().ToLowerInvariant() + ".png")); if ((Object)(object)val != (Object)null) { s_icons[value] = val; } } } private static Texture2D LoadTex(string path) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown if (!File.Exists(path)) { return null; } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (!ImageConversion.LoadImage(val, File.ReadAllBytes(path))) { return null; } return val; } private static void InitStyles() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_004c: 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_0059: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown //IL_0086: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Expected O, but got Unknown //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: 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_00e0: Expected O, but got Unknown //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Expected O, but got Unknown if (s_header == null) { GUIStyle val = new GUIStyle(GUI.skin.label) { fontSize = 13, fontStyle = (FontStyle)1, alignment = (TextAnchor)3 }; val.normal.textColor = ColGold; s_header = val; GUIStyle val2 = new GUIStyle(GUI.skin.label) { fontSize = 13, fontStyle = (FontStyle)1, alignment = (TextAnchor)3 }; val2.normal.textColor = ColWhite; s_title = val2; s_badge = new GUIStyle(GUI.skin.label) { fontSize = 11, fontStyle = (FontStyle)1, alignment = (TextAnchor)5 }; GUIStyle val3 = new GUIStyle(GUI.skin.label) { fontSize = 10, fontStyle = (FontStyle)1, alignment = (TextAnchor)3 }; val3.normal.textColor = ColWhite; s_barText = val3; GUIStyle val4 = new GUIStyle(GUI.skin.label) { fontSize = 11, wordWrap = true, alignment = (TextAnchor)0 }; val4.normal.textColor = ColDim; s_desc = val4; } } private static void DrawSolid(Rect rect, Color color) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) Color color2 = GUI.color; GUI.color = color; GUI.DrawTexture(rect, (Texture)(object)White); GUI.color = color2; } private static void DrawBorder(Rect rect, Color color, float thickness) { //IL_0016: 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_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_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) DrawSolid(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width, thickness), color); DrawSolid(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).yMax - thickness, ((Rect)(ref rect)).width, thickness), color); DrawSolid(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, thickness, ((Rect)(ref rect)).height), color); DrawSolid(new Rect(((Rect)(ref rect)).xMax - thickness, ((Rect)(ref rect)).y, thickness, ((Rect)(ref rect)).height), color); } } public static class ChuckLines { private static readonly string[] Lines = new string[60] { "I don't need a portal. When I run, I push Valheim under my boots.", "Trolls don't spawn in the Black Forest. They hide in caves hoping I don't go hiking.", "I don't need the Forsaken powers. The Forsaken activate Chuck Norse power when they're scared.", "When I fall off a mountain, the mountain takes blunt damage.", "I don't chop ancient oak trees with an axe. I stare at them until they turn themselves into fine wood.", "Deathsquitos don't sting me. They land, break their needles, and apologize for making noise.", "Odin didn't send me to the Tenth Realm to conquer it. He sent me here so Valhalla could get some sleep.", "The wind doesn't dictate which way my longship sails. Moder calls me to ask which way I want the breeze.", "I don't parry incoming blows. Weapons bounce off my chest and shatter out of embarrassment.", "Bonemass didn't need blunt weapons to die. He just needed to look me in the eyes for five seconds.", "I don't mine copper deposits. I roundhouse kick the ground and pick up thirty ingots.", "A troll threw a boulder at me once. Now that rock spends its afterlife as fine gravel on my porch.", "There is no theory of evolution in Valheim. Just a list of creatures Chuck Norse allowed to spawn.", "I don't sleep in a bed to skip the night. The sun rises early because it's afraid of my beard in the dark.", "Serpents don't attack my boat. They jump onboard, gut themselves, and cook into stew so I don't get angry.", "My rested bonus doesn't have a timer. Valheim gets a rested bonus when I close my eyes.", "I don't need a hammer to build a base. Timber snaps into place out of pure self-preservation.", "When lightning strikes near my longhouse, Thor looks out the window to make sure I'm not irritated.", "The swamp water isn't toxic. It's just sweating because it knows I'm wading through it.", "I don't dodge-roll. The realm shifts ten paces to the left to get out of my way.", "Fulings don't giggle when they see me. They file their wills and hand over their black metal.", "I drank an unfermented mead once. The barrel fermented itself in my stomach out of respect.", "I don't wear wolf armor to stay warm on the mountain. The blizzard puts on a coat when I walk past.", "The Haldor trader doesn't sell to me. He leaves his coin purse on the counter and steps backward slowly.", "I punched a draugr in the Meadow. Its soul landed in the Ashlands.", "When I do push-ups, I'm not lifting my body. I'm bench-pressing the World Tree.", "Greydwarfs don't throw stones at me. They hand them over with two hands and ask if I need a receipt.", "Moder wept. Not because of lore, but because I walked up the mountain without a cape.", "My bare knuckles deal pierce, slash, blunt, and emotional damage.", "The Ashlands didn't catch fire from magma. I struck a match there three winters ago.", "I don't tame wolves. They form a queue and argue over who gets to carry my firewood.", "Yagluth didn't fall. He sat down, and the Plains agreed that counted.", "I don't brew fire resistance mead. The mead brews itself when it hears my footsteps.", "Seekers don't spit at me. They spit out an apology and leave the trophy on the ground.", "I don't sail the Ocean. The Ocean sails around me and tries not to make waves.", "The Queen didn't have a weak spot. She had a Chuck spot, and I found it immediately.", "I don't repair my gear at a forge. The forge repairs itself and thanks me for stopping by.", "Eikthyr didn't drop a trophy. He handed it over and asked me to tell the others he went quietly.", "I don't use a cultivator. The dirt tills itself into neat rows out of professional courtesy.", "Abominations don't swing at me. They pull themselves up and lie down as fine wood.", "I don't need a belt for carry weight. The weight asks permission before it climbs into my pockets.", "Gjalls don't drop eggs on me. They set them down already cooked and fly off embarrassed.", "I missed a parry once. The realm rolled it back and agreed never to mention it.", "The Elder didn't guard the swamp key. He left it under the mat and went for a walk.", "I don't fish. The fish jump into the boat, fillet themselves, and suggest a lemon.", "Starred creatures aren't harder. They're the ones that wanted an autograph.", "I don't light campfires. The campfire lights itself so I won't have to look disappointed.", "Fader opened his mouth to roar. What came out was a very small 'sorry.'", "I don't need a portal tag. Every portal already knows my name and opens out of habit.", "The mist isn't thick. It's hiding so I won't assign it chores.", "I don't smelt ore. The smelter sees me coming and has the bars ready on the way in.", "Lox don't charge me. They kneel, and the Plains pretends that was always the plan.", "I don't eat food for the buffs. The food swallows its doubts and comes out as stamina.", "When I swim, the stamina bar looks away. It knows better than to move.", "I don't build a roof. The rain falls around the house, because getting me wet is above its pay.", "Draugr elites don't shout. They whisper 'there he is' and immediately reconsider.", "I don't ne