using System; using System.Collections; 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 BepInEx; using BepInEx.Configuration; using ExitGames.Client.Photon; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using Photon.Realtime; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("Furter.LegoSkin")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+e43a15cca221579c24fff2639608a1458e58b88f")] [assembly: AssemblyProduct("Furter.LegoSkin")] [assembly: AssemblyTitle("Furter.LegoSkin")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Furter.LegoSkin { [BepInPlugin("Furter.LegoSkin", "LEGO Skin", "5.0.0")] public class LegoSkinPlugin : BaseUnityPlugin { public static ConfigEntry CamDistance; public static ConfigEntry CamHeight; public static ConfigEntry CamFov; public static float CamDistOffset = 0f; public static float CamHeightOffset = 0f; public static float CamZoom = 3f; public static float GlobalYawNudge = -4f; public static bool DisableBody = false; public static ConfigEntry LegoScale; public static ConfigEntry SelectedCharacter; public static bool CameraEnabled = true; public static int CameraMode = 0; public static Transform HeadPivot; public static float ArmSpreadMult = 0.95f; public static float MouthSensitivity = 12f; public static float LegSwing = 1f; public static readonly string[] CameraModeNames = new string[2] { "1st Person", "BF2015 3rd Person" }; public static LegoSkinPlugin Instance; private string _pluginDir; private List _characters = new List(); private int _charIndex; private Harmony _harmony; private bool _legoApplied; private Character _lastCharacter; private bool _bonesDumped; private Item _lastHeldItem; private Dictionary _remoteSkins = new Dictionary(); private float _syncTimer; private static readonly Dictionary _texCache = new Dictionary(); private static readonly Dictionary _matCache = new Dictionary(); private List _allHeadDirs = new List(); private int _headIndex; private readonly Dictionary _partCharIdx = new Dictionary(); private List _allAccessoryPaths = new List(); private int _accessoryIndex = -1; private bool _treesReplaced; private GameObject _legoTreeTemplate; private float _treeNativeExtent; private readonly List _hiddenTreeRenderers = new List(); private readonly List _spawnedTrees = new List(); private GameObject _currentHeadMesh; private GameObject _currentAccessory; private Transform _headPivot; private int _handColorIndex; private static readonly Color[] HandColors = (Color[])(object)new Color[9] { new Color(0.95f, 0.8f, 0.2f, 1f), new Color(0.85f, 0.65f, 0.13f, 1f), new Color(0.45f, 0.3f, 0.14f, 1f), new Color(0.3f, 0.18f, 0.1f, 1f), new Color(0.95f, 0.9f, 0.8f, 1f), new Color(0.15f, 0.15f, 0.15f, 1f), new Color(0.9f, 0.9f, 0.9f, 1f), new Color(0.8f, 0f, 0f, 1f), new Color(0f, 0.5f, 0f, 1f) }; private static MethodInfo _loadImageMethod; private static MethodInfo _playEmoteMethod; private static readonly string[] TreeCanopyKeywords = new string[6] { "crown", "foliage", "leaves", "treeflower", "pineleaves", "pine berry" }; private static readonly string[] TreeTrunkKeywords = new string[3] { "trunk", "gianttree", "tree platform" }; private float _chromeMetallic = 1f; private float _chromeSmoothness = 0.9f; private Color _chromeTint = Color.white; private bool _hasChromeTint; private float _chromeEmission; private float _translucentAlpha = 1f; private string CurrentModelsDir { get { if (_characters.Count <= 0) { return null; } return Path.Combine(_pluginDir, _characters[_charIndex]); } } private void Awake() { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Expected O, but got Unknown //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Expected O, but got Unknown Instance = this; CamDistance = ((BaseUnityPlugin)this).Config.Bind("Camera", "Distance", 2f, new ConfigDescription("Camera distance", (AcceptableValueBase)(object)new AcceptableValueRange(1f, 10f), Array.Empty())); CamHeight = ((BaseUnityPlugin)this).Config.Bind("Camera", "Height", 0.3f, new ConfigDescription("Camera height", (AcceptableValueBase)(object)new AcceptableValueRange(-1f, 5f), Array.Empty())); CamFov = ((BaseUnityPlugin)this).Config.Bind("Camera", "FieldOfView", 75f, new ConfigDescription("Camera FOV", (AcceptableValueBase)(object)new AcceptableValueRange(15f, 170f), Array.Empty())); LegoScale = ((BaseUnityPlugin)this).Config.Bind("LEGO", "Scale", 2f, new ConfigDescription("Extra scale multiplier", (AcceptableValueBase)(object)new AcceptableValueRange(0.01f, 10f), Array.Empty())); SelectedCharacter = ((BaseUnityPlugin)this).Config.Bind("LEGO", "Character", "TwoFace", "Active character"); _pluginDir = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); ScanCharacters(); _playEmoteMethod = typeof(CharacterAnimations).GetMethod("PlayEmote", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); Type type = Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule"); if (type != null) { _loadImageMethod = type.GetMethod("LoadImage", new Type[2] { typeof(Texture2D), typeof(byte[]) }); } _harmony = new Harmony("Furter.LegoSkin"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"LEGO Skin v5.0.0 -- {_characters.Count} characters"); } private void ScanCharacters() { _characters.Clear(); _allHeadDirs.Clear(); _allAccessoryPaths.Clear(); string[] directories = Directory.GetDirectories(_pluginDir); foreach (string text in directories) { string fileName = Path.GetFileName(text); if (File.Exists(Path.Combine(text, "head.obj"))) { _characters.Add(fileName); _allHeadDirs.Add(text); } string[] files = Directory.GetFiles(text, "*.obj"); foreach (string text2 in files) { string text3 = Path.GetFileNameWithoutExtension(text2).ToLower(); if (text3.StartsWith("helmet") || text3.StartsWith("mask") || text3.StartsWith("hat") || text3.StartsWith("glasses") || text3.StartsWith("hair") || text3.StartsWith("accessory") || text3.StartsWith("visor") || text3.StartsWith("hood") || text3.StartsWith("crown") || text3.StartsWith("cap")) { _allAccessoryPaths.Add(text2); } } } _characters.Sort(); _allHeadDirs.Sort(); _charIndex = _characters.IndexOf(SelectedCharacter.Value); if (_charIndex < 0) { _charIndex = 0; } _headIndex = _charIndex; } private static string ChessSkinFor(string mn) { if (mn.Contains("king")) { return "Vader"; } if (mn.Contains("queen")) { return "Leia"; } if (mn.Contains("bishop")) { if (!mn.Contains("_f")) { return "QuiGon"; } return "ObiWan"; } if (mn.Contains("knight")) { return "BobaFett"; } if (mn.Contains("rook")) { if (!mn.Contains("_f")) { return "DarthMaul"; } return "Chewbacca"; } if (mn.Contains("pawn")) { if (!mn.Contains("_f")) { return "Batman"; } return "Stormtrooper"; } return null; } private void CyclePart(string cat) { if (_characters.Count != 0) { int value; int num = ((_partCharIdx.TryGetValue(cat, out value) ? value : _charIndex) + 1) % _characters.Count; _partCharIdx[cat] = num; ((BaseUnityPlugin)this).Logger.LogInfo((object)("Part [" + cat + "] -> " + _characters[num])); CleanupLego(); _legoApplied = false; } } private static string PartCategory(string partFile) { if (partFile.StartsWith("head")) { return "head"; } if (partFile.StartsWith("torso")) { return "torso"; } if (partFile.StartsWith("arms")) { return "arms"; } if (partFile.StartsWith("legs")) { return "legs"; } return null; } private string PartSourceDir(string partFile, string baseDir) { string text = PartCategory(partFile); if (text == null) { return baseDir; } if (_partCharIdx.TryGetValue(text, out var value) && value >= 0 && value < _characters.Count) { string text2 = Path.Combine(_pluginDir, _characters[value]); if (Directory.Exists(text2)) { return text2; } } return baseDir; } private void Update() { //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) Scene activeScene = SceneManager.GetActiveScene(); bool flag = ((Scene)(ref activeScene)).name.ToLowerInvariant().Contains("airport"); if (Input.GetKeyDown((KeyCode)286) || Input.GetKeyDown((KeyCode)334)) { CamZoom = ((CamZoom < 0.7f) ? 3f : 0.4f); CameraEnabled = true; Camera main = Camera.main; if ((Object)(object)main != (Object)null) { main.orthographic = false; } ((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("Camera: {0} (zoom {1:F1})", (CamZoom < 0.7f) ? "First Person" : "Third Person", CamZoom)); } if (flag && !DisableBody && (Input.GetKeyDown((KeyCode)287) || Input.GetKeyDown((KeyCode)335)) && _characters.Count > 1) { _charIndex = (_charIndex + 1) % _characters.Count; SelectedCharacter.Value = _characters[_charIndex]; ((BaseUnityPlugin)this).Logger.LogInfo((object)("Switched to: " + _characters[_charIndex])); _partCharIdx.Clear(); CleanupLego(); _legoApplied = false; BroadcastSkin(); } if (!DisableBody && (Object)(object)_lastCharacter != (Object)null && (Object)(object)_lastCharacter.data != (Object)null && _characters.Count > 0) { Item currentItem = _lastCharacter.data.currentItem; if ((Object)(object)currentItem != (Object)(object)_lastHeldItem) { _lastHeldItem = currentItem; if ((Object)(object)currentItem != (Object)null) { string text = null; MeshFilter[] componentsInChildren = ((Component)currentItem).GetComponentsInChildren(true); foreach (MeshFilter val in componentsInChildren) { if (!((Object)(object)val.sharedMesh == (Object)null)) { string text2 = ((Object)val.sharedMesh).name.ToLowerInvariant(); if (text2.Contains("king") || text2.Contains("queen") || text2.Contains("bishop") || text2.Contains("knight") || text2.Contains("rook") || text2.Contains("pawn")) { text = ChessSkinFor(text2); break; } } } if (text != null && _characters.Contains(text)) { int num = _characters.IndexOf(text); if (num >= 0 && num != _charIndex) { _charIndex = num; SelectedCharacter.Value = text; _partCharIdx.Clear(); CleanupLego(); _legoApplied = false; ((BaseUnityPlugin)this).Logger.LogInfo((object)("Chess pickup '" + ((Object)currentItem).name + "' -> wearing " + text)); } } } } } if (flag && !DisableBody && (Input.GetKeyDown((KeyCode)284) || Input.GetKeyDown((KeyCode)288))) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Refresh (F3) — reloading LEGO skin"); ScanCharacters(); CleanupLego(); _legoApplied = false; } if (Input.GetKey((KeyCode)273)) { CamZoom = Mathf.Max(0f, CamZoom - 4f * Time.deltaTime); } if (Input.GetKey((KeyCode)274)) { CamZoom = Mathf.Min(8f, CamZoom + 4f * Time.deltaTime); } if (Input.GetKeyDown((KeyCode)45)) { CamDistOffset -= 0.1f; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"cam dist offset {CamDistOffset:F2}"); } if (Input.GetKeyDown((KeyCode)61)) { CamDistOffset += 0.1f; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"cam dist offset {CamDistOffset:F2}"); } if (Input.GetKeyDown((KeyCode)91)) { CamHeightOffset -= 0.1f; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"cam height offset {CamHeightOffset:F2}"); } if (Input.GetKeyDown((KeyCode)93)) { CamHeightOffset += 0.1f; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"cam height offset {CamHeightOffset:F2}"); } if (Input.GetKeyDown((KeyCode)44)) { GlobalYawNudge -= 1f; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"global yaw nudge {GlobalYawNudge:F0}"); } if (Input.GetKeyDown((KeyCode)46)) { GlobalYawNudge += 1f; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"global yaw nudge {GlobalYawNudge:F0}"); } if (flag) { if (Input.GetKeyDown((KeyCode)257)) { CyclePart("head"); } if (Input.GetKeyDown((KeyCode)258)) { CyclePart("torso"); } if (Input.GetKeyDown((KeyCode)259)) { CyclePart("arms"); } if (Input.GetKeyDown((KeyCode)260)) { CyclePart("legs"); } if (Input.GetKeyDown((KeyCode)256)) { _partCharIdx.Clear(); CleanupLego(); _legoApplied = false; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Parts reset to current character"); } if (Input.GetKeyDown((KeyCode)270)) { ArmSpreadMult += 0.05f; CleanupLego(); _legoApplied = false; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"arm spread {ArmSpreadMult:F2}"); } if (Input.GetKeyDown((KeyCode)269)) { ArmSpreadMult = Mathf.Max(0.5f, ArmSpreadMult - 0.05f); CleanupLego(); _legoApplied = false; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"arm spread {ArmSpreadMult:F2}"); } if (Input.GetKeyDown((KeyCode)268)) { LegSwing += 0.15f; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"leg swing {LegSwing:F2}"); } if (Input.GetKeyDown((KeyCode)267)) { LegSwing = Mathf.Max(0f, LegSwing - 0.15f); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"leg swing {LegSwing:F2}"); } } if (Input.GetKeyDown((KeyCode)289)) { Player localPlayer = Player.localPlayer; if ((Object)(object)((localPlayer != null) ? localPlayer.character : null) != (Object)null) { DumpCharacterMesh(localPlayer.character); } } if (!DisableBody && Input.GetKeyDown((KeyCode)290) && _allHeadDirs.Count > 0) { _headIndex = (_headIndex + 1) % _allHeadDirs.Count; string fileName = Path.GetFileName(_allHeadDirs[_headIndex]); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Head swap -> " + fileName)); SwapHead(_allHeadDirs[_headIndex]); } if (!DisableBody && Input.GetKeyDown((KeyCode)285) && _allAccessoryPaths.Count > 0) { _accessoryIndex++; if (_accessoryIndex >= _allAccessoryPaths.Count) { _accessoryIndex = -1; } if (_accessoryIndex < 0) { RemoveAccessory(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Accessory removed"); } else { string text3 = _allAccessoryPaths[_accessoryIndex]; ((BaseUnityPlugin)this).Logger.LogInfo((object)("Accessory -> " + Path.GetFileName(text3))); ApplyAccessory(text3); } } if (Input.GetKeyDown((KeyCode)291)) { string text4 = Path.Combine(_pluginDir, "Screenshots"); Directory.CreateDirectory(text4); string text5 = $"lego_{DateTime.Now:yyyyMMdd_HHmmss_fff}.png"; ScreenCapture.CaptureScreenshot(Path.Combine(text4, text5)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Screenshot: " + text5)); } if (Input.GetKeyDown((KeyCode)292)) { Player localPlayer2 = Player.localPlayer; if ((Object)(object)((localPlayer2 != null) ? localPlayer2.character : null) != (Object)null) { DumpPeakReference(localPlayer2.character); } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)"F11: no local player character to capture"); } } if (Input.GetKeyDown((KeyCode)293)) { if (_treesReplaced) { RestoreTrees(); } else { ReplaceTrees(); } } if (DisableBody) { return; } Player localPlayer3 = Player.localPlayer; if ((Object)(object)localPlayer3 == (Object)null || (Object)(object)localPlayer3.character == (Object)null) { _legoApplied = false; _lastCharacter = null; } else { Character character = localPlayer3.character; if (!_legoApplied || (Object)(object)character != (Object)(object)_lastCharacter) { if ((Object)(object)character != (Object)(object)_lastCharacter) { CleanupLego(); _legoApplied = false; } _lastCharacter = character; ApplyLegoSkin(character); BroadcastSkin(); } } _syncTimer += Time.deltaTime; if (_syncTimer >= 0.5f) { _syncTimer = 0f; SyncRemotePlayers(); } } private static bool ContainsAny(string n, string[] keys) { foreach (string value in keys) { if (n.Contains(value)) { return true; } } return false; } private void EnsureLegoTreeTemplate() { //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Expected O, but got Unknown //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_legoTreeTemplate != (Object)null) { return; } string path = Path.Combine(_pluginDir, "_props", "LegoTree"); string text = Path.Combine(path, "legotree.obj"); if (!File.Exists(text)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("F12: legotree.obj not found at " + text)); return; } ObjResult objResult = ObjLoader.Load(text); Dictionary dictionary = ObjLoader.ParseMtl(Path.Combine(path, "legotree.mtl")); GameObject val = new GameObject("LegoTreeTemplate"); val.SetActive(false); val.AddComponent().sharedMesh = objResult.Mesh; MeshRenderer val2 = val.AddComponent(); Shader val3 = Shader.Find("Universal Render Pipeline/Lit"); Material[] array = (Material[])(object)new Material[objResult.MaterialNames.Length]; for (int i = 0; i < array.Length; i++) { MtlInfo mtlInfo = (dictionary.ContainsKey(objResult.MaterialNames[i]) ? dictionary[objResult.MaterialNames[i]] : null); Color val4 = ((mtlInfo != null && mtlInfo.HasKdColor) ? mtlInfo.KdColor : Color.gray); Material val5 = (((Object)(object)val3 != (Object)null) ? new Material(val3) : new Material(((Renderer)val2).material)); val5.SetColor("_BaseColor", val4); val5.color = val4; val5.SetFloat("_Smoothness", 0.85f); val5.SetFloat("_Metallic", 0f); array[i] = val5; } ((Renderer)val2).sharedMaterials = array; Bounds bounds = objResult.Mesh.bounds; Vector3 size = ((Bounds)(ref bounds)).size; _treeNativeExtent = Mathf.Max(size.x, Mathf.Max(size.y, size.z)); if (_treeNativeExtent < 0.001f) { _treeNativeExtent = 1f; } Object.DontDestroyOnLoad((Object)(object)val); _legoTreeTemplate = val; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"LEGO tree template: {objResult.Mesh.vertexCount}v, extent {_treeNativeExtent:F2}, {array.Length} colors"); } private void ReplaceTrees() { //IL_0106: 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_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02c1: Unknown result type (might be due to invalid IL or missing references) //IL_02cf: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) EnsureLegoTreeTemplate(); if ((Object)(object)_legoTreeTemplate == (Object)null) { return; } float result = 270f; float result2 = 0f; float result3 = 0f; float result4 = 1f; float result5 = 0f; string path = Path.Combine(_pluginDir, "_props", "LegoTree", "treeconfig.txt"); if (File.Exists(path)) { string[] array = File.ReadAllText(path).Split(new char[5] { ' ', ',', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); CultureInfo invariantCulture = CultureInfo.InvariantCulture; if (array.Length != 0) { float.TryParse(array[0], NumberStyles.Float, invariantCulture, out result); } if (array.Length > 1) { float.TryParse(array[1], NumberStyles.Float, invariantCulture, out result2); } if (array.Length > 2) { float.TryParse(array[2], NumberStyles.Float, invariantCulture, out result3); } if (array.Length > 3) { float.TryParse(array[3], NumberStyles.Float, invariantCulture, out result4); } if (array.Length > 4) { float.TryParse(array[4], NumberStyles.Float, invariantCulture, out result5); } } Quaternion rotation = Quaternion.Euler(result, result2, result3); int num = 0; int num2 = 0; MeshFilter[] array2 = Object.FindObjectsOfType(); foreach (MeshFilter val in array2) { if ((Object)(object)val == (Object)null || (Object)(object)val.sharedMesh == (Object)null) { continue; } MeshRenderer component = ((Component)val).GetComponent(); if ((Object)(object)component == (Object)null || !((Renderer)component).enabled) { continue; } string text = ((Object)val.sharedMesh).name.ToLowerInvariant(); bool flag = false; Material[] sharedMaterials = ((Renderer)component).sharedMaterials; if (sharedMaterials != null) { Material[] array3 = sharedMaterials; foreach (Material val2 in array3) { if ((Object)(object)val2 != (Object)null && ((Object)val2).name.ToLowerInvariant().Contains("palm")) { flag = true; break; } } } if (!flag && ContainsAny(text, TreeCanopyKeywords)) { ((Renderer)component).enabled = false; _hiddenTreeRenderers.Add((Renderer)(object)component); num2++; } else if (flag || text == "tree" || ContainsAny(text, TreeTrunkKeywords)) { Bounds bounds = ((Renderer)component).bounds; float num3 = Mathf.Max(((Bounds)(ref bounds)).size.x, Mathf.Max(((Bounds)(ref bounds)).size.y, ((Bounds)(ref bounds)).size.z)) / _treeNativeExtent * result4; GameObject val3 = Object.Instantiate(_legoTreeTemplate); ((Object)val3).name = "LegoTree"; val3.transform.position = new Vector3(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).min.y + result5, ((Bounds)(ref bounds)).center.z); val3.transform.rotation = rotation; val3.transform.localScale = Vector3.one * num3; val3.SetActive(true); _spawnedTrees.Add(val3); ((Renderer)component).enabled = false; _hiddenTreeRenderers.Add((Renderer)(object)component); num++; } } _treesReplaced = true; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"F12: {num} trees replaced (+{num2} canopies hidden). rot=({result},{result2},{result3}) scaleMult={result4} yOff={result5}"); } private void RestoreTrees() { foreach (GameObject spawnedTree in _spawnedTrees) { if ((Object)(object)spawnedTree != (Object)null) { Object.Destroy((Object)(object)spawnedTree); } } _spawnedTrees.Clear(); foreach (Renderer hiddenTreeRenderer in _hiddenTreeRenderers) { if ((Object)(object)hiddenTreeRenderer != (Object)null) { hiddenTreeRenderer.enabled = true; } } _hiddenTreeRenderers.Clear(); _treesReplaced = false; ((BaseUnityPlugin)this).Logger.LogInfo((object)"F12: trees restored"); } private void BroadcastSkin() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown try { if (PhotonNetwork.IsConnected && PhotonNetwork.InRoom && _characters.Count > 0) { Hashtable val = new Hashtable(); val[(object)"LegoSkin"] = _characters[_charIndex]; PhotonNetwork.LocalPlayer.SetCustomProperties(val, (Hashtable)null, (WebFlags)null); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Broadcast skin: " + _characters[_charIndex])); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Broadcast failed: " + ex.Message)); } } private void SyncRemotePlayers() { try { if (!PhotonNetwork.IsConnected || !PhotonNetwork.InRoom) { return; } List list = new List(); foreach (KeyValuePair remoteSkin in _remoteSkins) { if ((Object)(object)remoteSkin.Key == (Object)null) { list.Add(remoteSkin.Key); } } foreach (Character item in list) { _remoteSkins.Remove(item); } Player[] array = Object.FindObjectsByType((FindObjectsSortMode)0); foreach (Player val in array) { if ((Object)(object)val == (Object)(object)Player.localPlayer || (Object)(object)((val != null) ? val.character : null) == (Object)null) { continue; } PhotonView val2 = ((Component)val).GetComponent(); if ((Object)(object)val2 == (Object)null) { val2 = ((Component)val).GetComponentInChildren(); } if ((Object)(object)val2 == (Object)null) { val2 = ((Component)val).GetComponentInParent(); } if (((val2 != null) ? val2.Owner : null) == null || !((Dictionary)(object)val2.Owner.CustomProperties).TryGetValue((object)"LegoSkin", out object value)) { continue; } string text = value as string; if (!string.IsNullOrEmpty(text) && (!_remoteSkins.TryGetValue(val.character, out var value2) || !(value2 == text))) { string text2 = Path.Combine(_pluginDir, text); if (Directory.Exists(text2)) { CleanupLegoOn(val.character); ApplyLegoSkin(val.character, text2); _remoteSkins[val.character] = text; ((BaseUnityPlugin)this).Logger.LogInfo((object)("Applied remote skin: " + text + " on " + ((Object)val).name)); } } } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Remote sync error: " + ex.Message)); } } private void CleanupLegoOn(Character character) { if ((Object)(object)character == (Object)null) { return; } Transform[] componentsInChildren = ((Component)character).GetComponentsInChildren(true); foreach (Transform val in componentsInChildren) { if ((Object)(object)val != (Object)null && ((Object)((Component)val).gameObject).name == "LegoRoot") { Object.Destroy((Object)(object)((Component)val).gameObject); } } RestoreOriginalBody(character); } private void RestoreOriginalBody(Character character) { if ((Object)(object)character == (Object)null) { return; } SkinnedMeshRenderer mainRenderer = character.refs.mainRenderer; if ((Object)(object)mainRenderer != (Object)null) { ((Renderer)mainRenderer).shadowCastingMode = (ShadowCastingMode)1; } Renderer[] componentsInChildren = ((Component)character).GetComponentsInChildren(true); foreach (Renderer val in componentsInChildren) { if (((Object)((Component)val).gameObject).name.Contains("Lego_") || ((Object)((Component)val).gameObject).name.Contains("LegoMouth")) { continue; } SkinnedMeshRenderer val2 = (SkinnedMeshRenderer)(object)((val is SkinnedMeshRenderer) ? val : null); if (val2 != null) { ((Renderer)val2).shadowCastingMode = (ShadowCastingMode)1; continue; } MeshRenderer val3 = (MeshRenderer)(object)((val is MeshRenderer) ? val : null); if (val3 != null) { ((Renderer)val3).shadowCastingMode = (ShadowCastingMode)1; } } } private Transform FindBone(Transform[] bones, params string[] patterns) { if (bones == null) { return null; } foreach (string text in patterns) { foreach (Transform val in bones) { if ((Object)(object)val != (Object)null && ((Object)val).name.ToLower().Contains(text.ToLower())) { return val; } } } return null; } private Transform FindBoneExact(Transform[] bones, params string[] names) { if (bones == null) { return null; } foreach (string text in names) { foreach (Transform val in bones) { if ((Object)(object)val != (Object)null && ((Object)val).name == text) { return val; } } } return null; } private Texture2D LoadTexture(string path) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown if (!File.Exists(path)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Texture file not found: " + path)); return null; } byte[] array = File.ReadAllBytes(path); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true); if (_loadImageMethod != null) { if (!(bool)_loadImageMethod.Invoke(null, new object[2] { val, array })) { ((BaseUnityPlugin)this).Logger.LogWarning((object)$"LoadImage failed for: {Path.GetFileName(path)} ({array.Length} bytes)"); Object.Destroy((Object)(object)val); return null; } ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Loaded texture: {Path.GetFileName(path)} ({((Texture)val).width}x{((Texture)val).height})"); ((Texture)val).filterMode = (FilterMode)1; Object.DontDestroyOnLoad((Object)(object)val); return val; } ((BaseUnityPlugin)this).Logger.LogWarning((object)"ImageConversion.LoadImage not available"); Object.Destroy((Object)(object)val); return null; } private Material CreateMaterial(Material baseMat, Texture2D tex, Color baseColor, bool needsAlpha = false, Texture2D normalMap = null, bool isChrome = false, bool isGlass = false, bool isMatte = false) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown //IL_0045: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: 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_0130: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_0385: Unknown result type (might be due to invalid IL or missing references) //IL_038a: Unknown result type (might be due to invalid IL or missing references) //IL_039f: Unknown result type (might be due to invalid IL or missing references) //IL_03a7: Unknown result type (might be due to invalid IL or missing references) //IL_03ac: Unknown result type (might be due to invalid IL or missing references) //IL_03bc: Unknown result type (might be due to invalid IL or missing references) Shader val = Shader.Find("Universal Render Pipeline/Lit"); Material val2 = (((Object)(object)val != (Object)null) ? new Material(val) : new Material(baseMat)); if ((Object)(object)tex != (Object)null) { val2.mainTexture = (Texture)(object)tex; val2.SetTexture("_BaseMap", (Texture)(object)tex); val2.SetColor("_BaseColor", Color.white); val2.color = Color.white; } else { Texture2D val3 = new Texture2D(4, 4, (TextureFormat)4, false); Color[] array = (Color[])(object)new Color[16]; for (int i = 0; i < 16; i++) { array[i] = baseColor; } val3.SetPixels(array); val3.Apply(); ((Texture)val3).filterMode = (FilterMode)0; val2.mainTexture = (Texture)(object)val3; val2.SetTexture("_BaseMap", (Texture)(object)val3); val2.SetColor("_BaseColor", Color.white); val2.color = Color.white; } val2.SetFloat("_Smoothness", isChrome ? _chromeSmoothness : (isMatte ? 0.12f : 0.9f)); val2.SetFloat("_Metallic", isChrome ? _chromeMetallic : 0f); val2.SetFloat("_GlossMapScale", 1f); if (isChrome && _hasChromeTint) { val2.SetColor("_BaseColor", _chromeTint); val2.color = _chromeTint; } if (isChrome && _chromeEmission > 0f) { val2.EnableKeyword("_EMISSION"); Color val4 = (_hasChromeTint ? _chromeTint : Color.white) * _chromeEmission; val4.a = 1f; val2.SetColor("_EmissionColor", val4); if ((Object)(object)tex != (Object)null) { val2.SetTexture("_EmissionMap", (Texture)(object)tex); } val2.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1; } if ((Object)(object)normalMap != (Object)null) { val2.SetTexture("_BumpMap", (Texture)(object)normalMap); val2.SetFloat("_BumpScale", 1f); val2.EnableKeyword("_NORMALMAP"); } if (needsAlpha) { val2.SetFloat("_AlphaClip", 1f); val2.SetFloat("_Cutoff", 0.5f); val2.EnableKeyword("_ALPHATEST_ON"); val2.renderQueue = 2450; } if (isGlass) { val2.SetFloat("_Surface", 1f); val2.SetFloat("_Blend", 0f); val2.SetOverrideTag("RenderType", "Transparent"); val2.SetInt("_SrcBlend", 5); val2.SetInt("_DstBlend", 10); val2.SetInt("_ZWrite", 0); val2.DisableKeyword("_ALPHATEST_ON"); val2.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); val2.DisableKeyword("_ALPHAPREMULTIPLY_ON"); Color val5 = default(Color); ((Color)(ref val5))..ctor(0.62f, 0.8f, 0.92f, 0.3f); val2.SetColor("_BaseColor", val5); val2.color = val5; val2.SetFloat("_Smoothness", 0.95f); val2.SetFloat("_Metallic", 0.1f); val2.renderQueue = 3050; } if (_translucentAlpha < 0.999f && !isGlass) { val2.SetFloat("_Surface", 1f); val2.SetFloat("_Blend", 0f); val2.SetOverrideTag("RenderType", "Transparent"); val2.SetInt("_SrcBlend", 5); val2.SetInt("_DstBlend", 10); val2.SetInt("_ZWrite", 0); val2.DisableKeyword("_ALPHATEST_ON"); val2.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); Color color = val2.GetColor("_BaseColor"); color.a = _translucentAlpha; val2.SetColor("_BaseColor", color); Color color2 = val2.color; color2.a = _translucentAlpha; val2.color = color2; val2.renderQueue = 3000; } if (val2.HasProperty("_Cull")) { val2.SetFloat("_Cull", 0f); } Object.DontDestroyOnLoad((Object)(object)val2); return val2; } private Material[] BuildMaterials(string modelsDir, string partFile, Material baseMat, Dictionary texCache, Dictionary matCache, ObjResult result, bool isChrome = false) { //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0173: 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_031c: Unknown result type (might be due to invalid IL or missing references) Dictionary dictionary = ObjLoader.ParseMtl(Path.Combine(modelsDir, partFile + ".mtl")); HashSet hashSet = new HashSet(); string path = Path.Combine(modelsDir, "glass.txt"); if (File.Exists(path)) { string[] array = File.ReadAllLines(path); foreach (string text in array) { if (!string.IsNullOrWhiteSpace(text)) { hashSet.Add(text.Trim()); } } } HashSet hashSet2 = new HashSet(); string path2 = Path.Combine(modelsDir, "matte.txt"); if (File.Exists(path2)) { string[] array = File.ReadAllLines(path2); foreach (string text2 in array) { if (!string.IsNullOrWhiteSpace(text2)) { hashSet2.Add(text2.Trim()); } } } Material[] array2 = (Material[])(object)new Material[result.MaterialNames.Length]; for (int j = 0; j < result.MaterialNames.Length; j++) { string text3 = result.MaterialNames[j]; MtlInfo mtlInfo = (dictionary.ContainsKey(text3) ? dictionary[text3] : null); if (mtlInfo == null && dictionary.Count > 0) { using Dictionary.Enumerator enumerator = dictionary.GetEnumerator(); if (enumerator.MoveNext()) { KeyValuePair current = enumerator.Current; mtlInfo = current.Value; text3 = current.Key; } } string text4 = mtlInfo?.TexFile; Color baseColor = ((mtlInfo != null && mtlInfo.HasKdColor) ? mtlInfo.KdColor : Color.white); bool flag = partFile.Contains("head") && text4 != null && (text4.Contains("Face") || text4.Contains("face")); bool flag2 = hashSet.Contains(text3); bool flag3 = hashSet2.Contains("all") || hashSet2.Contains(partFile) || hashSet2.Contains(text3); string key = modelsDir + "|" + text3 + (flag ? "_alpha" : "") + (isChrome ? "_chrome" : "") + (flag2 ? "_glass" : "") + (flag3 ? "_matte" : "") + ((_translucentAlpha < 0.999f) ? ("_tl" + _translucentAlpha.ToString("0.00")) : ""); if (!matCache.ContainsKey(key)) { Texture2D tex = null; if (text4 != null) { string key2 = modelsDir + "|" + text4; if (!texCache.ContainsKey(key2)) { texCache[key2] = LoadTexture(Path.Combine(modelsDir, text4)); } tex = texCache[key2]; } Texture2D normalMap = null; string text5 = mtlInfo?.NormalFile; if (text5 != null) { string key3 = modelsDir + "|" + text5; if (!texCache.ContainsKey(key3)) { texCache[key3] = LoadTexture(Path.Combine(modelsDir, text5)); } normalMap = texCache[key3]; } matCache[key] = CreateMaterial(baseMat, tex, baseColor, flag, normalMap, isChrome, flag2, flag3); } array2[j] = matCache[key]; } return array2; } private void ApplyLegoSkin(Character character, string overrideDir = null) { //IL_0916: Unknown result type (might be due to invalid IL or missing references) //IL_092a: Unknown result type (might be due to invalid IL or missing references) //IL_092f: Unknown result type (might be due to invalid IL or missing references) //IL_0955: Unknown result type (might be due to invalid IL or missing references) //IL_095c: Expected O, but got Unknown //IL_0972: Unknown result type (might be due to invalid IL or missing references) //IL_0979: Unknown result type (might be due to invalid IL or missing references) //IL_0996: Unknown result type (might be due to invalid IL or missing references) //IL_09a9: Unknown result type (might be due to invalid IL or missing references) //IL_09b7: Unknown result type (might be due to invalid IL or missing references) //IL_09c1: Unknown result type (might be due to invalid IL or missing references) //IL_0944: Unknown result type (might be due to invalid IL or missing references) //IL_0adf: Unknown result type (might be due to invalid IL or missing references) //IL_0ae6: Expected O, but got Unknown //IL_0c2b: Unknown result type (might be due to invalid IL or missing references) //IL_0c30: Unknown result type (might be due to invalid IL or missing references) //IL_0d94: Unknown result type (might be due to invalid IL or missing references) //IL_0db0: Unknown result type (might be due to invalid IL or missing references) //IL_0ddc: Unknown result type (might be due to invalid IL or missing references) //IL_0ead: Unknown result type (might be due to invalid IL or missing references) //IL_0e66: Unknown result type (might be due to invalid IL or missing references) //IL_0e8f: Unknown result type (might be due to invalid IL or missing references) //IL_0e11: Unknown result type (might be due to invalid IL or missing references) //IL_0e3a: Unknown result type (might be due to invalid IL or missing references) //IL_0f7e: Unknown result type (might be due to invalid IL or missing references) //IL_0f37: Unknown result type (might be due to invalid IL or missing references) //IL_0f60: Unknown result type (might be due to invalid IL or missing references) //IL_0ee2: Unknown result type (might be due to invalid IL or missing references) //IL_0f0b: Unknown result type (might be due to invalid IL or missing references) //IL_1117: Unknown result type (might be due to invalid IL or missing references) //IL_111c: Unknown result type (might be due to invalid IL or missing references) //IL_13e7: Unknown result type (might be due to invalid IL or missing references) //IL_13ed: Expected O, but got Unknown //IL_1163: Unknown result type (might be due to invalid IL or missing references) //IL_1168: Unknown result type (might be due to invalid IL or missing references) //IL_19d2: Unknown result type (might be due to invalid IL or missing references) //IL_19d7: Unknown result type (might be due to invalid IL or missing references) //IL_19ea: Unknown result type (might be due to invalid IL or missing references) //IL_19f0: Unknown result type (might be due to invalid IL or missing references) //IL_19fa: Unknown result type (might be due to invalid IL or missing references) //IL_1a00: Unknown result type (might be due to invalid IL or missing references) //IL_1a0a: Unknown result type (might be due to invalid IL or missing references) //IL_1a10: Unknown result type (might be due to invalid IL or missing references) //IL_1a1a: Unknown result type (might be due to invalid IL or missing references) //IL_1410: Unknown result type (might be due to invalid IL or missing references) //IL_1415: Unknown result type (might be due to invalid IL or missing references) //IL_1539: Unknown result type (might be due to invalid IL or missing references) //IL_1540: Expected O, but got Unknown //IL_155b: Unknown result type (might be due to invalid IL or missing references) //IL_1569: Unknown result type (might be due to invalid IL or missing references) //IL_157a: Unknown result type (might be due to invalid IL or missing references) //IL_14cc: Unknown result type (might be due to invalid IL or missing references) //IL_14d4: Unknown result type (might be due to invalid IL or missing references) //IL_14d9: Unknown result type (might be due to invalid IL or missing references) //IL_14de: Unknown result type (might be due to invalid IL or missing references) //IL_1730: Unknown result type (might be due to invalid IL or missing references) //IL_1737: Expected O, but got Unknown //IL_1752: Unknown result type (might be due to invalid IL or missing references) //IL_1754: Unknown result type (might be due to invalid IL or missing references) //IL_1765: Unknown result type (might be due to invalid IL or missing references) //IL_1776: Unknown result type (might be due to invalid IL or missing references) //IL_17d0: Unknown result type (might be due to invalid IL or missing references) //IL_17d5: Unknown result type (might be due to invalid IL or missing references) //IL_17de: Unknown result type (might be due to invalid IL or missing references) //IL_17e7: Unknown result type (might be due to invalid IL or missing references) //IL_17ec: Unknown result type (might be due to invalid IL or missing references) //IL_17fd: Unknown result type (might be due to invalid IL or missing references) //IL_1806: Unknown result type (might be due to invalid IL or missing references) //IL_180b: Unknown result type (might be due to invalid IL or missing references) //IL_1880: Unknown result type (might be due to invalid IL or missing references) //IL_1885: Unknown result type (might be due to invalid IL or missing references) //IL_188e: Unknown result type (might be due to invalid IL or missing references) //IL_1895: Unknown result type (might be due to invalid IL or missing references) //IL_189f: Unknown result type (might be due to invalid IL or missing references) //IL_18a6: Unknown result type (might be due to invalid IL or missing references) //IL_1979: Unknown result type (might be due to invalid IL or missing references) //IL_197e: Unknown result type (might be due to invalid IL or missing references) string text = overrideDir ?? CurrentModelsDir; if (text == null || !Directory.Exists(text)) { return; } SkinnedMeshRenderer mainRenderer = character.refs.mainRenderer; Transform[] array = ((mainRenderer != null) ? mainRenderer.bones : null); Transform val = ((mainRenderer != null) ? mainRenderer.rootBone : null); if (!_bonesDumped && array != null) { _bonesDumped = true; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"=== PEAK Skeleton: {array.Length} bones ==="); Transform[] array2 = array; foreach (Transform val2 in array2) { if ((Object)(object)val2 != (Object)null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)(" Bone: " + ((Object)val2).name + " (parent: " + (((Object)(object)val2.parent != (Object)null) ? ((Object)val2.parent).name : "none") + ")")); } } if ((Object)(object)val != (Object)null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)(" RootBone: " + ((Object)val).name)); } Type type = ((object)character).GetType(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"=== Death/Ragdoll Methods ==="); MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { string text2 = methodInfo.Name.ToLower(); if (text2.Contains("die") || text2.Contains("death") || text2.Contains("dead") || text2.Contains("ragdoll") || text2.Contains("skeleton") || text2.Contains("kill") || text2.Contains("respawn") || text2.Contains("alive") || text2.Contains("health") || text2.Contains("damage") || text2.Contains("knockdown") || text2.Contains("downed")) { ((BaseUnityPlugin)this).Logger.LogInfo((object)(" " + methodInfo.Name + "(" + string.Join(", ", Array.ConvertAll(methodInfo.GetParameters(), (ParameterInfo p) => p.ParameterType.Name + " " + p.Name)) + ") -> " + methodInfo.ReturnType.Name)); } } FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { string text3 = fieldInfo.Name.ToLower(); if (text3.Contains("die") || text3.Contains("death") || text3.Contains("dead") || text3.Contains("ragdoll") || text3.Contains("skeleton") || text3.Contains("alive") || text3.Contains("health") || text3.Contains("downed")) { ((BaseUnityPlugin)this).Logger.LogInfo((object)(" Field: " + fieldInfo.Name + " (" + fieldInfo.FieldType.Name + ")")); } } PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (PropertyInfo propertyInfo in properties) { string text4 = propertyInfo.Name.ToLower(); if (text4.Contains("die") || text4.Contains("death") || text4.Contains("dead") || text4.Contains("ragdoll") || text4.Contains("skeleton") || text4.Contains("alive") || text4.Contains("health") || text4.Contains("downed")) { ((BaseUnityPlugin)this).Logger.LogInfo((object)(" Prop: " + propertyInfo.Name + " (" + propertyInfo.PropertyType.Name + ")")); } } } Transform val3 = FindBoneExact(array, "Hip") ?? FindBone(array, "hip", "pelvis"); Transform val4 = FindBoneExact(array, "Mid") ?? FindBone(array, "mid", "spine"); Transform val5 = FindBoneExact(array, "Head") ?? FindBone(array, "head"); Transform val6 = FindBoneExact(array, "Arm_L") ?? FindBone(array, "arm_l", "upperarm_l", "shoulder_l"); Transform val7 = FindBoneExact(array, "Arm_R") ?? FindBone(array, "arm_r", "upperarm_r", "shoulder_r"); Transform val8 = FindBoneExact(array, "Leg_L") ?? FindBone(array, "leg_l", "thigh_l"); Transform val9 = FindBoneExact(array, "Leg_R") ?? FindBone(array, "leg_r", "thigh_r"); Transform val10 = FindBoneExact(array, "Hand_L") ?? FindBone(array, "hand_l"); Transform val11 = FindBoneExact(array, "Hand_R") ?? FindBone(array, "hand_r"); Transform val12 = val3 ?? val ?? ((Component)character).transform; ((BaseUnityPlugin)this).Logger.LogInfo((object)("Bones: Hip=" + ((val3 != null) ? ((Object)val3).name : null) + " Mid=" + ((val4 != null) ? ((Object)val4).name : null) + " Head=" + ((val5 != null) ? ((Object)val5).name : null) + " ArmL=" + ((val6 != null) ? ((Object)val6).name : null) + " ArmR=" + ((val7 != null) ? ((Object)val7).name : null) + " LegL=" + ((val8 != null) ? ((Object)val8).name : null) + " LegR=" + ((val9 != null) ? ((Object)val9).name : null))); float result = 1f; string path = Path.Combine(text, "scale.txt"); if (File.Exists(path)) { float.TryParse(File.ReadAllText(path).Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out result); if (result <= 0f) { result = 1f; } } float num = 4.06f; string path2 = Path.Combine(text, "head.obj"); if (File.Exists(path2)) { float num2 = 0f; string[] array3 = File.ReadAllLines(path2); foreach (string text5 in array3) { if (text5.StartsWith("v ")) { string[] array4 = text5.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array4.Length >= 3 && float.TryParse(array4[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && result2 > num2) { num2 = result2; } } } if (num2 > 1f) { num = num2; } } Dictionary dictionary = LoadPeakConstants(); float value; float num3 = (dictionary.TryGetValue("characterHeight", out value) ? value : 1.7f); float num4 = num3 / num * LegoScale.Value * result; float result3 = 180f; string path3 = Path.Combine(text, "rotation.txt"); if (File.Exists(path3)) { float.TryParse(File.ReadAllText(path3).Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out result3); } bool flag = Mathf.Abs(result3 - 180f) < 1f; bool flag2 = !flag; if (File.Exists(Path.Combine(text, "noflipz.txt"))) { flag2 = false; } float result4 = 0f; string path4 = Path.Combine(text, "yaw_offset.txt"); if (File.Exists(path4)) { float.TryParse(File.ReadAllText(path4).Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out result4); } float num5 = val12.position.y - 0.9f; RaycastHit val13 = default(RaycastHit); if (Physics.Raycast(val12.position, Vector3.down, ref val13, 5f)) { num5 = ((RaycastHit)(ref val13)).point.y; } GameObject val14 = new GameObject("LegoRoot"); val14.transform.SetParent(val12, false); val14.transform.localScale = Vector3.one * num4; val14.transform.localRotation = Quaternion.Euler(0f, result3, 0f); val14.transform.position = new Vector3(val12.position.x, num5, val12.position.z); LegoStabilizer legoStabilizer = val14.AddComponent(); legoStabilizer.hipBone = val12; legoStabilizer.baseYRotation = result3 + result4; legoStabilizer.heightOffset = 0f; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Scale={num4:F3} PeakH={num3:F3} ModelH={num:F2} CharScale={result:F2} GroundY={num5:F2}"); Shader val15 = null; if ((Object)(object)mainRenderer != (Object)null && (Object)(object)((Renderer)mainRenderer).sharedMaterial != (Object)null) { val15 = ((Renderer)mainRenderer).sharedMaterial.shader; ((BaseUnityPlugin)this).Logger.LogInfo((object)("Using game shader: " + ((Object)val15).name)); } if ((Object)(object)val15 == (Object)null) { val15 = Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("Universal Render Pipeline/Simple Lit") ?? Shader.Find("Standard"); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Fallback shader: " + (((val15 != null) ? ((Object)val15).name : null) ?? "NULL"))); } Material val16 = new Material(val15); Dictionary texCache = _texCache; Dictionary matCache = _matCache; bool flag3 = File.Exists(Path.Combine(text, "arms_l.obj")); bool flag4 = File.Exists(Path.Combine(text, "legs_l.obj")); bool flag5 = File.Exists(Path.Combine(text, "chrome.txt")); _chromeMetallic = 1f; _chromeSmoothness = 0.9f; _hasChromeTint = false; _chromeEmission = 0f; if (flag5) { string[] array5 = File.ReadAllText(Path.Combine(text, "chrome.txt")).Trim().Split(new char[5] { ' ', ',', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); CultureInfo invariantCulture = CultureInfo.InvariantCulture; if (array5.Length >= 1) { float.TryParse(array5[0], NumberStyles.Float, invariantCulture, out _chromeMetallic); } if (array5.Length >= 2) { float.TryParse(array5[1], NumberStyles.Float, invariantCulture, out _chromeSmoothness); } if (array5.Length >= 5) { float result5 = 1f; float result6 = 1f; float result7 = 1f; float.TryParse(array5[2], NumberStyles.Float, invariantCulture, out result5); float.TryParse(array5[3], NumberStyles.Float, invariantCulture, out result6); float.TryParse(array5[4], NumberStyles.Float, invariantCulture, out result7); _chromeTint = new Color(result5, result6, result7, 1f); _hasChromeTint = true; } if (array5.Length >= 6) { float.TryParse(array5[5], NumberStyles.Float, invariantCulture, out _chromeEmission); } ((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format(" chrome: metallic={0} smoothness={1} tint={2} emission={3}", _chromeMetallic, _chromeSmoothness, _hasChromeTint ? ((object)Unsafe.As(ref _chromeTint)/*cast due to .constrained prefix*/).ToString() : "none", _chromeEmission)); } bool flag6 = File.Exists(Path.Combine(text, "cape.txt")); float num6 = num; float num7 = num6 * 0.714f; float value2; float num8 = num6 * (dictionary.TryGetValue("torsoY", out value2) ? value2 : 0.493f); float value3; float num9 = num6 * (dictionary.TryGetValue("armX", out value3) ? value3 : 0.148f) * ArmSpreadMult; float value4; float num10 = num6 * (dictionary.TryGetValue("armY", out value4) ? value4 : 0.591f); float value5; float num11 = num6 * (dictionary.TryGetValue("legX", out value5) ? value5 : 0.086f); float value6; float num12 = num6 * (dictionary.TryGetValue("legY", out value6) ? value6 : 0.222f); List list = new List(); list.Add(new PartDef("torso", "Mid", new Vector3(0f, num8, 0f), 0.4f)); list.Add(new PartDef("hips", null, Vector3.zero, 0f)); list.Add(new PartDef("head", "Head", new Vector3(0f, num7, 0f), 0.5f)); if (flag3) { if (flag) { list.Add(new PartDef("arms_l", "Arm_R", new Vector3(0f - num9, num10, 0f), 1f)); list.Add(new PartDef("arms_r", "Arm_L", new Vector3(num9, num10, 0f), 1f)); } else { list.Add(new PartDef("arms_l", "Arm_L", new Vector3(0f - num9, num10, 0f), 1f)); list.Add(new PartDef("arms_r", "Arm_R", new Vector3(num9, num10, 0f), 1f)); } } else { list.Add(new PartDef("arms", null, Vector3.zero, 0f)); } if (flag4) { if (flag) { list.Add(new PartDef("legs_l", "Leg_R", new Vector3(0f - num11, num12, 0f), 0.7f)); list.Add(new PartDef("legs_r", "Leg_L", new Vector3(num11, num12, 0f), 0.7f)); } else { list.Add(new PartDef("legs_l", "Leg_L", new Vector3(0f - num11, num12, 0f), 0.7f)); list.Add(new PartDef("legs_r", "Leg_R", new Vector3(num11, num12, 0f), 0.7f)); } } else { list.Add(new PartDef("legs", null, Vector3.zero, 0f)); } Dictionary dictionary2 = new Dictionary(); if ((Object)(object)val4 != (Object)null) { dictionary2["Mid"] = val4; } if ((Object)(object)val5 != (Object)null) { dictionary2["Head"] = val5; } if ((Object)(object)val6 != (Object)null) { dictionary2["Arm_L"] = val6; } if ((Object)(object)val7 != (Object)null) { dictionary2["Arm_R"] = val7; } if ((Object)(object)val8 != (Object)null) { dictionary2["Leg_L"] = val8; } if ((Object)(object)val9 != (Object)null) { dictionary2["Leg_R"] = val9; } if ((Object)(object)val10 != (Object)null) { dictionary2["Hand_L"] = val10; } if ((Object)(object)val11 != (Object)null) { dictionary2["Hand_R"] = val11; } foreach (PartDef item in list) { string text6 = PartSourceDir(item.file, text); string path5 = Path.Combine(text6, item.file + ".obj"); if (!File.Exists(path5)) { continue; } ObjResult objResult = ObjLoader.Load(path5); if (objResult.Mesh.vertexCount == 0) { continue; } if (flag2) { Vector3[] vertices = objResult.Mesh.vertices; Vector3[] normals = objResult.Mesh.normals; for (int num13 = 0; num13 < vertices.Length; num13++) { vertices[num13] = new Vector3(vertices[num13].x, vertices[num13].y, 0f - vertices[num13].z); } for (int num14 = 0; num14 < normals.Length; num14++) { normals[num14] = new Vector3(normals[num14].x, normals[num14].y, 0f - normals[num14].z); } objResult.Mesh.vertices = vertices; objResult.Mesh.normals = normals; for (int num15 = 0; num15 < objResult.Mesh.subMeshCount; num15++) { int[] triangles = objResult.Mesh.GetTriangles(num15); for (int num16 = 0; num16 < triangles.Length; num16 += 3) { int num17 = triangles[num16]; triangles[num16] = triangles[num16 + 2]; triangles[num16 + 2] = num17; } objResult.Mesh.SetTriangles(triangles, num15); } objResult.Mesh.RecalculateBounds(); } string text7 = item.file; string path6 = Path.Combine(text6, text7 + ".mtl"); if (!File.Exists(path6)) { string text8 = item.file.Split(new char[1] { '_' })[0]; path6 = Path.Combine(text6, text8 + ".mtl"); text7 = text8; } bool isChrome = flag5; string path7 = Path.Combine(text6, item.file + "_chrome.txt"); if (File.Exists(path7)) { isChrome = true; _chromeMetallic = 1f; _chromeSmoothness = 0.9f; string[] array6 = File.ReadAllText(path7).Trim().Split(new char[5] { ' ', ',', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); CultureInfo invariantCulture2 = CultureInfo.InvariantCulture; if (array6.Length >= 1) { float.TryParse(array6[0], NumberStyles.Float, invariantCulture2, out _chromeMetallic); } if (array6.Length >= 2) { float.TryParse(array6[1], NumberStyles.Float, invariantCulture2, out _chromeSmoothness); } ((BaseUnityPlugin)this).Logger.LogInfo((object)$" {item.file} chrome: metallic={_chromeMetallic} smoothness={_chromeSmoothness}"); } _translucentAlpha = 1f; string path8 = Path.Combine(text6, item.file + "_translucent.txt"); if (File.Exists(path8)) { float.TryParse(File.ReadAllText(path8).Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out _translucentAlpha); ((BaseUnityPlugin)this).Logger.LogInfo((object)$" {item.file} translucent alpha={_translucentAlpha}"); } Material[] materials = (Material[])((!File.Exists(path6)) ? ((Array)new Material[1] { new Material(val16) }) : ((Array)BuildMaterials(text6, text7, val16, texCache, matCache, objResult, isChrome))); if (item.boneName != null && dictionary2.ContainsKey(item.boneName)) { Vector3 val17 = item.pivot; string path9 = Path.Combine(text6, item.file + "_offset.txt"); if (File.Exists(path9)) { string[] array7 = File.ReadAllText(path9).Trim().Split(new char[3] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries); CultureInfo invariantCulture3 = CultureInfo.InvariantCulture; float result8 = 0f; float result9 = 0f; float result10 = 0f; if (array7.Length >= 1) { float.TryParse(array7[0], NumberStyles.Float, invariantCulture3, out result8); } if (array7.Length >= 2) { float.TryParse(array7[1], NumberStyles.Float, invariantCulture3, out result9); } if (array7.Length >= 3) { float.TryParse(array7[2], NumberStyles.Float, invariantCulture3, out result10); } val17 += new Vector3(result8, result9, result10); ((BaseUnityPlugin)this).Logger.LogInfo((object)$" {item.file} offset: ({result8},{result9},{result10})"); } GameObject val18 = new GameObject("Lego_" + item.file + "_pivot"); val18.transform.SetParent(val14.transform, false); val18.transform.localPosition = val17; val18.transform.localScale = Vector3.one; val18.transform.localRotation = Quaternion.identity; LegoBoneTracker legoBoneTracker = val18.AddComponent(); legoBoneTracker.targetBone = dictionary2[item.boneName]; legoBoneTracker.influence = item.influence; legoBoneTracker.flipModel = flag; if (item.file == "head") { legoBoneTracker.isHead = true; legoBoneTracker.positionFollow = 0f; } if (item.file == "torso") { legoBoneTracker.isTorso = true; legoBoneTracker.characterTransform = val12; legoBoneTracker.positionFollow = 1f; } if (item.file.StartsWith("arms")) { legoBoneTracker.isArm = true; legoBoneTracker.characterTransform = val12; legoBoneTracker.positionFollow = 0f; bool flag7 = (flag ? item.file.Contains("_r") : item.file.Contains("_l")); legoBoneTracker.armSide = (flag7 ? 1f : (-1f)); legoBoneTracker.isLeftArm = flag7; string key = ((item.boneName == "Arm_L") ? "Hand_L" : "Hand_R"); if (dictionary2.ContainsKey(key)) { legoBoneTracker.handBone = dictionary2[key]; } } if (item.file.StartsWith("legs")) { legoBoneTracker.isLeg = true; legoBoneTracker.legSide = (item.file.Contains("_r") ? 1f : (-1f)); legoBoneTracker.characterTransform = val12; legoBoneTracker.positionFollow = 0f; } GameObject val19 = new GameObject("Lego_" + item.file); val19.transform.SetParent(val18.transform, false); val19.transform.localPosition = -val17; val19.transform.localScale = Vector3.one; val19.transform.localRotation = Quaternion.identity; string path10 = Path.Combine(text, item.file + "_yaw.txt"); if (File.Exists(path10) && float.TryParse(File.ReadAllText(path10).Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result11)) { Quaternion val20 = Quaternion.Euler(0f, result11, 0f); val19.transform.localRotation = val20 * val19.transform.localRotation; val19.transform.localPosition = val20 * val19.transform.localPosition; ((BaseUnityPlugin)this).Logger.LogInfo((object)$" {item.file} yaw: {result11} deg"); } string path11 = Path.Combine(text, item.file + "_lift.txt"); if (File.Exists(path11) && float.TryParse(File.ReadAllText(path11).Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result12)) { Vector3 localPosition = val19.transform.localPosition; val19.transform.localPosition = new Vector3(localPosition.x, localPosition.y + result12, localPosition.z); ((BaseUnityPlugin)this).Logger.LogInfo((object)$" {item.file} lift: {result12}"); } val19.AddComponent().mesh = objResult.Mesh; MeshRenderer obj = val19.AddComponent(); ((Renderer)obj).materials = materials; ((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1; ((Renderer)obj).receiveShadows = true; if (item.file == "head") { _headPivot = val18.transform; if (overrideDir == null) { HeadPivot = val18.transform; } _currentHeadMesh = val19; val19.AddComponent(); } if (item.file == "torso" && flag6 && objResult.Mesh.subMeshCount >= 2) { ExtractClothCape(objResult.Mesh, materials, val18.transform, -item.pivot); } ((BaseUnityPlugin)this).Logger.LogInfo((object)$" {item.file} -> {item.boneName} (pivot, {objResult.Mesh.vertexCount}v)"); } else { GameObject val21 = new GameObject("Lego_" + item.file); val21.transform.SetParent(val14.transform, false); val21.transform.localPosition = Vector3.zero; val21.transform.localScale = Vector3.one; val21.transform.localRotation = Quaternion.identity; val21.AddComponent().mesh = objResult.Mesh; MeshRenderer obj2 = val21.AddComponent(); ((Renderer)obj2).materials = materials; ((Renderer)obj2).shadowCastingMode = (ShadowCastingMode)1; ((Renderer)obj2).receiveShadows = true; ((BaseUnityPlugin)this).Logger.LogInfo((object)$" {item.file} -> root (static, {objResult.Mesh.vertexCount}v)"); } } HideOriginalBody(character); _legoApplied = true; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"LEGO {_characters[_charIndex]} applied! ({list.Count} parts)"); if (overrideDir == null && _characters[_charIndex] == "Batman") { TryGiveRescueClaw(character); } } private void TryGiveRescueClaw(Character character) { try { Type type = Type.GetType("ItemDatabase, Assembly-CSharp"); if (type == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"ItemDatabase type not found"); return; } Object[] array = Resources.FindObjectsOfTypeAll(type); if (array == null || array.Length == 0) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"No ItemDatabase"); return; } Object obj = array[0]; FieldInfo field = type.GetField("Objects", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"Objects field not found"); return; } if (!(field.GetValue(obj) is IList list)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"Objects list is null"); return; } ((BaseUnityPlugin)this).Logger.LogInfo((object)$"ItemDatabase: {list.Count} items"); object obj2 = null; int itemIdx = -1; for (int i = 0; i < list.Count; i++) { object obj3 = list[i]; if (obj3 != null) { string text = obj3.ToString().ToLower(); ((BaseUnityPlugin)this).Logger.LogInfo((object)$" Item[{i}]: {obj3} ({obj3.GetType().Name})"); if (text.Contains("rescue") || text.Contains("hook") || text.Contains("claw")) { obj2 = obj3; itemIdx = i; ((BaseUnityPlugin)this).Logger.LogInfo((object)$" >> RESCUE ITEM FOUND at index {i}: {obj3}"); } } } if (obj2 != null) { GiveItemToPlayer(character, itemIdx, obj2); } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)"Rescue hook item not found in database"); } } catch (Exception arg) { ((BaseUnityPlugin)this).Logger.LogWarning((object)$"RescueClaw error: {arg}"); } } private void GiveItemToPlayer(Character character, int itemIdx, object itemDef) { try { Type type = ((object)character).GetType(); MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { string text = methodInfo.Name.ToLower(); if (text.Contains("item") || text.Contains("backpack") || text.Contains("equip")) { ((BaseUnityPlugin)this).Logger.LogInfo((object)(" Char." + methodInfo.Name + "(" + string.Join(", ", Array.ConvertAll(methodInfo.GetParameters(), (ParameterInfo p) => p.ParameterType.Name + " " + p.Name)) + ")")); } } Type type2 = itemDef.GetType(); ((BaseUnityPlugin)this).Logger.LogInfo((object)(" Item type: " + type2.FullName)); FieldInfo[] fields = type2.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { ((BaseUnityPlugin)this).Logger.LogInfo((object)$" Item field: {fieldInfo.Name} = {fieldInfo.GetValue(itemDef)}"); } PropertyInfo[] properties = type2.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (PropertyInfo propertyInfo in properties) { try { ((BaseUnityPlugin)this).Logger.LogInfo((object)$" Item prop: {propertyInfo.Name} = {propertyInfo.GetValue(itemDef)}"); } catch { ((BaseUnityPlugin)this).Logger.LogInfo((object)(" Item prop: " + propertyInfo.Name + " (error reading)")); } } MethodInfo method = type.GetMethod("PutItemInBackpack", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method != null) { ParameterInfo[] parameters = method.GetParameters(); ((BaseUnityPlugin)this).Logger.LogInfo((object)(" PutItemInBackpack(" + string.Join(", ", Array.ConvertAll(parameters, (ParameterInfo p) => p.ParameterType.Name)) + ")")); if (parameters.Length == 1) { method.Invoke(character, new object[1] { itemDef }); ((BaseUnityPlugin)this).Logger.LogInfo((object)" >> Item given to backpack!"); ColorItemGold(character); } } else { ((BaseUnityPlugin)this).Logger.LogInfo((object)" PutItemInBackpack not found on Character"); } } catch (Exception arg) { ((BaseUnityPlugin)this).Logger.LogWarning((object)$"GiveItem error: {arg}"); } } private void ColorItemGold(Character character) { //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) try { Renderer[] componentsInChildren = ((Component)character).GetComponentsInChildren(true); foreach (Renderer val in componentsInChildren) { if (!((Object)((Component)val).gameObject).name.ToLower().Contains("hook") && !((Object)((Component)val).gameObject).name.ToLower().Contains("rescue") && !((Object)((Component)val).gameObject).name.ToLower().Contains("claw")) { continue; } Material[] materials = val.materials; foreach (Material val2 in materials) { val2.color = new Color(1f, 0.84f, 0f, 1f); if (val2.HasProperty("_BaseColor")) { val2.SetColor("_BaseColor", new Color(1f, 0.84f, 0f, 1f)); } val2.SetFloat("_Metallic", 1f); val2.SetFloat("_Smoothness", 0.9f); } ((BaseUnityPlugin)this).Logger.LogInfo((object)(" Colored gold: " + ((Object)((Component)val).gameObject).name)); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("ColorGold error: " + ex.Message)); } } private void SwapHead(string sourceDir) { //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Expected O, but got Unknown //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Expected O, but got Unknown //IL_011a: 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_0166: 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_0323: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Expected O, but got Unknown //IL_0344: Unknown result type (might be due to invalid IL or missing references) //IL_0346: Unknown result type (might be due to invalid IL or missing references) //IL_0357: Unknown result type (might be due to invalid IL or missing references) //IL_0368: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_headPivot == (Object)null) { return; } Transform val = _headPivot.Find("Lego_head"); if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)((Component)val).gameObject); } string path = Path.Combine(sourceDir, "head.obj"); if (!File.Exists(path)) { return; } ObjResult objResult = ObjLoader.Load(path); if (objResult.Mesh.vertexCount == 0) { return; } string path2 = Path.Combine(sourceDir, "noflipz.txt"); float result = 180f; string path3 = Path.Combine(sourceDir, "rotation.txt"); if (File.Exists(path3)) { float.TryParse(File.ReadAllText(path3).Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out result); } if (!(Mathf.Abs(result - 180f) < 1f) && !File.Exists(path2)) { Vector3[] vertices = objResult.Mesh.vertices; Vector3[] normals = objResult.Mesh.normals; for (int i = 0; i < vertices.Length; i++) { vertices[i] = new Vector3(vertices[i].x, vertices[i].y, 0f - vertices[i].z); } for (int j = 0; j < normals.Length; j++) { normals[j] = new Vector3(normals[j].x, normals[j].y, 0f - normals[j].z); } objResult.Mesh.vertices = vertices; objResult.Mesh.normals = normals; for (int k = 0; k < objResult.Mesh.subMeshCount; k++) { int[] triangles = objResult.Mesh.GetTriangles(k); for (int l = 0; l < triangles.Length; l += 3) { int num = triangles[l]; triangles[l] = triangles[l + 2]; triangles[l + 2] = num; } objResult.Mesh.SetTriangles(triangles, k); } objResult.Mesh.RecalculateBounds(); } Material val2 = new Material(Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("Standard")); Dictionary texCache = _texCache; Dictionary matCache = _matCache; Material[] materials = (Material[])((!File.Exists(Path.Combine(sourceDir, "head.mtl"))) ? ((Array)new Material[1] { new Material(val2) }) : ((Array)BuildMaterials(sourceDir, "head", val2, texCache, matCache, objResult))); float num2 = 4.06f; string path4 = Path.Combine(sourceDir, "head.obj"); float num3 = 0f; string[] array = File.ReadAllLines(path4); foreach (string text in array) { if (text.StartsWith("v ")) { string[] array2 = text.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array2.Length >= 3 && float.TryParse(array2[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && result2 > num3) { num3 = result2; } } } if (num3 > 1f) { num2 = num3; } Vector3 val3 = default(Vector3); ((Vector3)(ref val3))..ctor(0f, num2 * 0.714f, 0f); GameObject val4 = new GameObject("Lego_head"); val4.transform.SetParent(_headPivot, false); val4.transform.localPosition = -val3; val4.transform.localScale = Vector3.one; val4.transform.localRotation = Quaternion.identity; val4.AddComponent().mesh = objResult.Mesh; MeshRenderer obj = val4.AddComponent(); ((Renderer)obj).materials = materials; ((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1; ((Renderer)obj).receiveShadows = true; val4.AddComponent(); _currentHeadMesh = val4; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Head swapped from {Path.GetFileName(sourceDir)} ({objResult.Mesh.vertexCount}v)"); } private void ApplyAccessory(string objPath) { //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Expected O, but got Unknown //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Expected O, but got Unknown //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Expected O, but got Unknown //IL_0336: Unknown result type (might be due to invalid IL or missing references) //IL_0338: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Unknown result type (might be due to invalid IL or missing references) //IL_035a: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) RemoveAccessory(); if ((Object)(object)_headPivot == (Object)null) { return; } string directoryName = Path.GetDirectoryName(objPath); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(objPath); ObjResult objResult = ObjLoader.Load(objPath); if (objResult.Mesh.vertexCount == 0) { return; } string path = Path.Combine(directoryName, "noflipz.txt"); float result = 180f; string path2 = Path.Combine(directoryName, "rotation.txt"); if (File.Exists(path2)) { float.TryParse(File.ReadAllText(path2).Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out result); } if (!(Mathf.Abs(result - 180f) < 1f) && !File.Exists(path)) { Vector3[] vertices = objResult.Mesh.vertices; Vector3[] normals = objResult.Mesh.normals; for (int i = 0; i < vertices.Length; i++) { vertices[i] = new Vector3(vertices[i].x, vertices[i].y, 0f - vertices[i].z); } for (int j = 0; j < normals.Length; j++) { normals[j] = new Vector3(normals[j].x, normals[j].y, 0f - normals[j].z); } objResult.Mesh.vertices = vertices; objResult.Mesh.normals = normals; for (int k = 0; k < objResult.Mesh.subMeshCount; k++) { int[] triangles = objResult.Mesh.GetTriangles(k); for (int l = 0; l < triangles.Length; l += 3) { int num = triangles[l]; triangles[l] = triangles[l + 2]; triangles[l + 2] = num; } objResult.Mesh.SetTriangles(triangles, k); } objResult.Mesh.RecalculateBounds(); } Material val = new Material(Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("Standard")); Dictionary texCache = _texCache; Dictionary matCache = _matCache; Material[] materials = (Material[])((!File.Exists(Path.Combine(directoryName, fileNameWithoutExtension + ".mtl"))) ? ((Array)new Material[1] { new Material(val) }) : ((Array)BuildMaterials(directoryName, fileNameWithoutExtension, val, texCache, matCache, objResult))); float num2 = 4.06f; string path3 = Path.Combine(directoryName, "head.obj"); if (File.Exists(path3)) { float num3 = 0f; string[] array = File.ReadAllLines(path3); foreach (string text in array) { if (text.StartsWith("v ")) { string[] array2 = text.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array2.Length >= 3 && float.TryParse(array2[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && result2 > num3) { num3 = result2; } } } if (num3 > 1f) { num2 = num3; } } Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(0f, num2 * 0.714f, 0f); GameObject val3 = new GameObject("Lego_accessory_" + fileNameWithoutExtension); val3.transform.SetParent(_headPivot, false); val3.transform.localPosition = -val2; val3.transform.localScale = Vector3.one; val3.transform.localRotation = Quaternion.identity; val3.AddComponent().mesh = objResult.Mesh; MeshRenderer obj = val3.AddComponent(); ((Renderer)obj).materials = materials; ((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1; ((Renderer)obj).receiveShadows = true; val3.AddComponent(); _currentAccessory = val3; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Accessory: {fileNameWithoutExtension} from {Path.GetFileName(directoryName)} ({objResult.Mesh.vertexCount}v)"); } private void RemoveAccessory() { if ((Object)(object)_currentAccessory != (Object)null) { Object.Destroy((Object)(object)_currentAccessory); _currentAccessory = null; } } private void CycleHandColor() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) _handColorIndex = (_handColorIndex + 1) % HandColors.Length; Color val = HandColors[_handColorIndex]; string[] array = new string[9] { "Yellow", "Gold", "Brown", "Dark Brown", "Peach", "Black", "White", "Red", "Green" }; string text = ((_handColorIndex < array.Length) ? array[_handColorIndex] : $"Color {_handColorIndex}"); Transform[] array2 = Object.FindObjectsByType((FindObjectsSortMode)0); foreach (Transform val2 in array2) { if ((Object)(object)val2 == (Object)null || ((Object)((Component)val2).gameObject).name != "LegoRoot") { continue; } Renderer[] componentsInChildren = ((Component)val2).GetComponentsInChildren(true); foreach (Renderer val3 in componentsInChildren) { if (!((Object)((Component)val3).gameObject).name.ToLower().Contains("arm")) { continue; } Material[] materials = val3.materials; foreach (Material val4 in materials) { val4.mainTexture = null; if (val4.HasProperty("_BaseMap")) { val4.SetTexture("_BaseMap", (Texture)null); } val4.color = val; if (val4.HasProperty("_BaseColor")) { val4.SetColor("_BaseColor", val); } } } } ((BaseUnityPlugin)this).Logger.LogInfo((object)("Hand color -> " + text)); } private void ExtractClothCape(Mesh torsoMesh, Material[] materials, Transform parent, Vector3 offset) { //IL_007d: 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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Expected O, but got Unknown //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0266: 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_0276: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_029d: Expected O, but got Unknown //IL_02fe: Unknown result type (might be due to invalid IL or missing references) //IL_0307: Unknown result type (might be due to invalid IL or missing references) if (torsoMesh.subMeshCount < 2) { return; } int[] triangles = torsoMesh.GetTriangles(1); if (triangles.Length == 0) { return; } Vector3[] vertices = torsoMesh.vertices; Vector3[] normals = torsoMesh.normals; Vector2[] uv = torsoMesh.uv; Dictionary dictionary = new Dictionary(); List list = new List(); List list2 = new List(); List list3 = new List(); List list4 = new List(); foreach (int num in triangles) { if (!dictionary.ContainsKey(num)) { dictionary[num] = list.Count; list.Add(vertices[num]); list2.Add((num < normals.Length) ? normals[num] : Vector3.up); list3.Add((num < uv.Length) ? uv[num] : Vector2.zero); } list4.Add(dictionary[num]); } Dictionary cache = new Dictionary(); List list5 = new List(); for (int j = 0; j < list4.Count; j += 3) { int num2 = list4[j]; int num3 = list4[j + 1]; int num4 = list4[j + 2]; int orCreateMidpoint = GetOrCreateMidpoint(num2, num3, list, list2, list3, cache); int orCreateMidpoint2 = GetOrCreateMidpoint(num3, num4, list, list2, list3, cache); int orCreateMidpoint3 = GetOrCreateMidpoint(num4, num2, list, list2, list3, cache); list5.AddRange(new int[12] { num2, orCreateMidpoint, orCreateMidpoint3, orCreateMidpoint, num3, orCreateMidpoint2, orCreateMidpoint3, orCreateMidpoint2, num4, orCreateMidpoint, orCreateMidpoint2, orCreateMidpoint3 }); } list4 = list5; Mesh val = new Mesh(); val.vertices = list.ToArray(); val.normals = list2.ToArray(); val.uv = list3.ToArray(); val.triangles = list4.ToArray(); val.RecalculateBounds(); val.RecalculateNormals(); GameObject val2 = new GameObject("Lego_cape_cloth"); val2.transform.SetParent(parent, false); val2.transform.localPosition = offset + new Vector3(0f, -0.15f, -0.02f); val2.transform.localScale = new Vector3(1.03f, 1.02f, 1.03f); val2.transform.localRotation = Quaternion.identity; val2.AddComponent().mesh = val; Material val3 = ((materials.Length > 1) ? new Material(materials[1]) : new Material(materials[0])); Color val4 = default(Color); ((Color)(ref val4))..ctor(0.35f, 0.35f, 0.38f, 1f); val3.SetTexture("_BumpMap", (Texture)null); val3.SetTexture("_DetailAlbedoMap", (Texture)null); val3.SetTexture("_DetailNormalMap", (Texture)null); val3.DisableKeyword("_NORMALMAP"); val3.DisableKeyword("_DETAIL_MULX2"); val3.SetColor("_BaseColor", val4); val3.color = val4; val3.SetFloat("_Smoothness", 0.15f); val3.SetFloat("_Metallic", 0f); val3.renderQueue = 2001; MeshRenderer obj = val2.AddComponent(); ((Renderer)obj).material = val3; ((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1; ((Renderer)obj).receiveShadows = true; torsoMesh.SetTriangles(new int[0], 1); ((BaseUnityPlugin)this).Logger.LogInfo((object)$" Cape: {val.vertexCount}v, static (no physics)"); } private int GetOrCreateMidpoint(int a, int b, List verts, List norms, List uvs, Dictionary cache) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005c: 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_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0080: 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_008f: Unknown result type (might be due to invalid IL or missing references) long key = ((a < b) ? (((long)a << 32) | (uint)b) : (((long)b << 32) | (uint)a)); if (cache.TryGetValue(key, out var value)) { return value; } value = verts.Count; verts.Add((verts[a] + verts[b]) * 0.5f); Vector3 val = norms[a] + norms[b]; norms.Add(((Vector3)(ref val)).normalized); uvs.Add((uvs[a] + uvs[b]) * 0.5f); cache[key] = value; return value; } private void DumpCharacterMesh(Character character) { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected O, but got Unknown //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0423: Unknown result type (might be due to invalid IL or missing references) //IL_0428: Unknown result type (might be due to invalid IL or missing references) //IL_042c: Unknown result type (might be due to invalid IL or missing references) //IL_0431: Unknown result type (might be due to invalid IL or missing references) //IL_0435: Unknown result type (might be due to invalid IL or missing references) //IL_043a: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_04d3: Unknown result type (might be due to invalid IL or missing references) //IL_04df: Unknown result type (might be due to invalid IL or missing references) //IL_04eb: Unknown result type (might be due to invalid IL or missing references) //IL_0510: Unknown result type (might be due to invalid IL or missing references) //IL_051f: Unknown result type (might be due to invalid IL or missing references) //IL_052e: Unknown result type (might be due to invalid IL or missing references) //IL_053d: Unknown result type (might be due to invalid IL or missing references) //IL_055b: Unknown result type (might be due to invalid IL or missing references) //IL_0567: Unknown result type (might be due to invalid IL or missing references) //IL_0573: Unknown result type (might be due to invalid IL or missing references) string text = Path.Combine(_pluginDir, "MeshDump"); Directory.CreateDirectory(text); SkinnedMeshRenderer[] componentsInChildren = ((Component)character).GetComponentsInChildren(true); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"=== MESH DUMP: {componentsInChildren.Length} SkinnedMeshRenderers ==="); HashSet hashSet = new HashSet(); int num = 0; SkinnedMeshRenderer[] array = componentsInChildren; foreach (SkinnedMeshRenderer val in array) { if ((Object)(object)val.sharedMesh == (Object)null) { continue; } Mesh val2 = new Mesh(); val.BakeMesh(val2); string arg = ((Object)((Component)val).gameObject).name.Replace(" ", "_"); using (StreamWriter streamWriter = new StreamWriter(Path.Combine(text, $"{arg}_{num}.obj"))) { streamWriter.WriteLine("# PEAK Mesh Dump: " + ((Object)((Component)val).gameObject).name); streamWriter.WriteLine($"# Vertices: {val2.vertexCount} Triangles: {val2.triangles.Length / 3}"); Vector3[] vertices = val2.vertices; Vector3[] normals = val2.normals; Vector2[] uv = val2.uv; Matrix4x4 localToWorldMatrix = ((Component)val).transform.localToWorldMatrix; for (int j = 0; j < vertices.Length; j++) { Vector3 val3 = ((Matrix4x4)(ref localToWorldMatrix)).MultiplyPoint3x4(vertices[j]); streamWriter.WriteLine($"v {val3.x:F6} {val3.y:F6} {val3.z:F6}"); } for (int k = 0; k < uv.Length; k++) { streamWriter.WriteLine($"vt {uv[k].x:F6} {uv[k].y:F6}"); } for (int l = 0; l < normals.Length; l++) { Vector3 val4 = ((Matrix4x4)(ref localToWorldMatrix)).MultiplyVector(normals[l]); Vector3 normalized = ((Vector3)(ref val4)).normalized; streamWriter.WriteLine($"vn {normalized.x:F6} {normalized.y:F6} {normalized.z:F6}"); } int[] triangles = val2.triangles; for (int m = 0; m < triangles.Length; m += 3) { int num2 = triangles[m] + 1; int num3 = triangles[m + 1] + 1; int num4 = triangles[m + 2] + 1; streamWriter.WriteLine($"f {num2}/{num2}/{num2} {num3}/{num3}/{num3} {num4}/{num4}/{num4}"); } } ((BaseUnityPlugin)this).Logger.LogInfo((object)$" Dumped: {arg}_{num}.obj ({val2.vertexCount}v)"); if (val.bones != null) { Transform[] bones = val.bones; foreach (Transform val5 in bones) { if ((Object)(object)val5 != (Object)null) { hashSet.Add(val5); } } } Object.Destroy((Object)(object)val2); num++; } using (StreamWriter streamWriter2 = new StreamWriter(Path.Combine(text, "skeleton.json"))) { streamWriter2.WriteLine("{"); streamWriter2.WriteLine(" \"bones\": ["); List list = new List(hashSet); List list2 = new List(); foreach (Transform item in list) { Transform val6 = item; while ((Object)(object)val6 != (Object)null && !list2.Contains(val6)) { list2.Add(val6); if ((Object)(object)val6 == (Object)(object)((Component)character).transform) { break; } val6 = val6.parent; } } for (int num5 = 0; num5 < list2.Count; num5++) { Transform val7 = list2[num5]; Vector3 position = val7.position; Vector3 localScale = val7.localScale; Quaternion localRotation = val7.localRotation; string text2 = (((Object)(object)val7.parent != (Object)null && list2.Contains(val7.parent)) ? ((Object)val7.parent).name : ""); string text3 = ((num5 < list2.Count - 1) ? "," : ""); streamWriter2.WriteLine(" {"); streamWriter2.WriteLine(" \"name\": \"" + ((Object)val7).name + "\","); streamWriter2.WriteLine(" \"parent\": \"" + text2 + "\","); streamWriter2.WriteLine($" \"world_pos\": [{position.x:F6}, {position.y:F6}, {position.z:F6}],"); streamWriter2.WriteLine($" \"local_rot\": [{localRotation.x:F6}, {localRotation.y:F6}, {localRotation.z:F6}, {localRotation.w:F6}],"); streamWriter2.WriteLine($" \"local_scale\": [{localScale.x:F6}, {localScale.y:F6}, {localScale.z:F6}]"); streamWriter2.WriteLine(" }" + text3); } streamWriter2.WriteLine(" ]"); streamWriter2.WriteLine("}"); } ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Skeleton dumped: {componentsInChildren.Length} meshes, {hashSet.Count} bones -> {text}"); } private void DumpBoneQuaternions(Character character) { //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) SkinnedMeshRenderer mainRenderer = character.refs.mainRenderer; if (((mainRenderer != null) ? mainRenderer.bones : null) == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"No bones found"); return; } string text = Path.Combine(_pluginDir, "bone_quaternions.txt"); using (StreamWriter streamWriter = new StreamWriter(text)) { streamWriter.WriteLine($"PEAK Bone Quaternions - {DateTime.Now}"); streamWriter.WriteLine("Character: " + ((Object)((Component)character).gameObject).name); streamWriter.WriteLine($"Bones: {mainRenderer.bones.Length}"); streamWriter.WriteLine(); streamWriter.WriteLine(string.Format("{0,-30} {1,-50} {2,-40} {3,-35}", "Name", "LocalRot (x,y,z,w)", "LocalPos (x,y,z)", "EulerAngles (x,y,z)")); streamWriter.WriteLine(new string('-', 155)); Transform[] bones = mainRenderer.bones; foreach (Transform val in bones) { if (!((Object)(object)val == (Object)null)) { Quaternion localRotation = val.localRotation; Vector3 localPosition = val.localPosition; Vector3 localEulerAngles = val.localEulerAngles; streamWriter.WriteLine($"{((Object)val).name,-30} ({localRotation.x,8:F4}, {localRotation.y,8:F4}, {localRotation.z,8:F4}, {localRotation.w,8:F4}) ({localPosition.x,8:F4}, {localPosition.y,8:F4}, {localPosition.z,8:F4}) ({localEulerAngles.x,8:F2}, {localEulerAngles.y,8:F2}, {localEulerAngles.z,8:F2})"); } } } ((BaseUnityPlugin)this).Logger.LogInfo((object)("Bone quaternions dumped to: " + text)); } private Dictionary LoadPeakConstants() { Dictionary dictionary = new Dictionary(); string path = Path.Combine(_pluginDir, "peak_constants.txt"); if (!File.Exists(path)) { return dictionary; } string[] array = File.ReadAllLines(path); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length == 0 || text.StartsWith("#")) { continue; } int num = text.IndexOf('='); if (num > 0) { string key = text.Substring(0, num).Trim(); if (float.TryParse(text.Substring(num + 1).Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result)) { dictionary[key] = result; } } } return dictionary; } private void DumpPeakReference(Character character) { //IL_03a4: Unknown result type (might be due to invalid IL or missing references) //IL_03a9: Unknown result type (might be due to invalid IL or missing references) //IL_03ae: Unknown result type (might be due to invalid IL or missing references) //IL_03b3: Unknown result type (might be due to invalid IL or missing references) //IL_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_03cf: Unknown result type (might be due to invalid IL or missing references) //IL_03e6: Unknown result type (might be due to invalid IL or missing references) //IL_03eb: Unknown result type (might be due to invalid IL or missing references) //IL_029d: Unknown result type (might be due to invalid IL or missing references) //IL_02a4: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: Unknown result type (might be due to invalid IL or missing references) //IL_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_0415: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_0346: Unknown result type (might be due to invalid IL or missing references) //IL_0349: 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_02e5: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_042d: Unknown result type (might be due to invalid IL or missing references) //IL_037d: Unknown result type (might be due to invalid IL or missing references) //IL_0389: Unknown result type (might be due to invalid IL or missing references) //IL_0363: Unknown result type (might be due to invalid IL or missing references) //IL_036f: Unknown result type (might be due to invalid IL or missing references) //IL_045f: Unknown result type (might be due to invalid IL or missing references) //IL_0464: Unknown result type (might be due to invalid IL or missing references) //IL_046c: Unknown result type (might be due to invalid IL or missing references) //IL_046e: Unknown result type (might be due to invalid IL or missing references) //IL_0473: Unknown result type (might be due to invalid IL or missing references) //IL_0458: Unknown result type (might be due to invalid IL or missing references) //IL_0451: Unknown result type (might be due to invalid IL or missing references) //IL_055b: Unknown result type (might be due to invalid IL or missing references) //IL_0562: Expected O, but got Unknown //IL_05c8: Unknown result type (might be due to invalid IL or missing references) //IL_05cd: Unknown result type (might be due to invalid IL or missing references) //IL_05e3: Unknown result type (might be due to invalid IL or missing references) //IL_05fc: Unknown result type (might be due to invalid IL or missing references) //IL_0615: Unknown result type (might be due to invalid IL or missing references) //IL_0647: Unknown result type (might be due to invalid IL or missing references) //IL_064c: Unknown result type (might be due to invalid IL or missing references) //IL_0657: Unknown result type (might be due to invalid IL or missing references) //IL_066a: Unknown result type (might be due to invalid IL or missing references) //IL_069b: Unknown result type (might be due to invalid IL or missing references) //IL_06a0: Unknown result type (might be due to invalid IL or missing references) //IL_06b6: Unknown result type (might be due to invalid IL or missing references) //IL_06cf: Unknown result type (might be due to invalid IL or missing references) //IL_06e8: Unknown result type (might be due to invalid IL or missing references) //IL_0810: Unknown result type (might be due to invalid IL or missing references) //IL_0815: Unknown result type (might be due to invalid IL or missing references) //IL_0b32: Unknown result type (might be due to invalid IL or missing references) //IL_0b5a: Unknown result type (might be due to invalid IL or missing references) //IL_0b64: Unknown result type (might be due to invalid IL or missing references) //IL_0b69: Unknown result type (might be due to invalid IL or missing references) //IL_0b6e: Unknown result type (might be due to invalid IL or missing references) //IL_0b46: Unknown result type (might be due to invalid IL or missing references) //IL_0b4b: Unknown result type (might be due to invalid IL or missing references) //IL_0b50: Unknown result type (might be due to invalid IL or missing references) //IL_0b55: Unknown result type (might be due to invalid IL or missing references) //IL_0be4: Unknown result type (might be due to invalid IL or missing references) //IL_0bfd: Unknown result type (might be due to invalid IL or missing references) //IL_0c16: Unknown result type (might be due to invalid IL or missing references) //IL_0c30: Unknown result type (might be due to invalid IL or missing references) //IL_0c4b: Unknown result type (might be due to invalid IL or missing references) //IL_0c66: Unknown result type (might be due to invalid IL or missing references) SkinnedMeshRenderer mainRenderer = character.refs.mainRenderer; if ((Object)(object)mainRenderer == (Object)null || (Object)(object)mainRenderer.sharedMesh == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"F11: character.refs.mainRenderer is not a usable SkinnedMeshRenderer"); return; } string text = Path.Combine(_pluginDir, "PeakReference"); Directory.CreateDirectory(text); Mesh sharedMesh = mainRenderer.sharedMesh; Transform[] bones = mainRenderer.bones; Matrix4x4[] bindposes = sharedMesh.bindposes; Transform rootBone = mainRenderer.rootBone; Func func = delegate(Transform b) { //IL_0046: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)b == (Object)null || bindposes == null) { return (Vector3?)null; } for (int i = 0; i < bones.Length; i++) { if ((Object)(object)bones[i] == (Object)(object)b && i < bindposes.Length) { Matrix4x4 inverse2 = ((Matrix4x4)(ref bindposes[i])).inverse; return Vector4.op_Implicit(((Matrix4x4)(ref inverse2)).GetColumn(3)); } } return (Vector3?)null; }; Transform val = FindBoneExact(bones, "Hip") ?? FindBone(bones, "hip", "pelvis"); Transform arg = FindBoneExact(bones, "Mid") ?? FindBone(bones, "mid", "spine"); Transform arg2 = FindBoneExact(bones, "Head") ?? FindBone(bones, "head"); Transform arg3 = FindBoneExact(bones, "Arm_L") ?? FindBone(bones, "arm_l", "upperarm_l", "shoulder_l"); Transform arg4 = FindBoneExact(bones, "Arm_R") ?? FindBone(bones, "arm_r", "upperarm_r", "shoulder_r"); Transform arg5 = FindBoneExact(bones, "Leg_L") ?? FindBone(bones, "leg_l", "thigh_l"); Transform arg6 = FindBoneExact(bones, "Foot_R") ?? FindBone(bones, "foot", "ankle", "toe"); int vAxis = 1; int lAxis = 0; Vector3? val2 = func(arg2); Vector3? val3 = func(arg6); if (val2.HasValue && val3.HasValue) { Vector3 val4 = val2.Value - val3.Value; vAxis = ((!(Mathf.Abs(val4.x) >= Mathf.Abs(val4.y)) || !(Mathf.Abs(val4.x) >= Mathf.Abs(val4.z))) ? ((!(Mathf.Abs(val4.z) >= Mathf.Abs(val4.y))) ? 1 : 2) : 0); } Vector3? val5 = func(arg3); Vector3? val6 = func(arg4); if (val5.HasValue && val6.HasValue) { Vector3 val7 = val5.Value - val6.Value; lAxis = ((Mathf.Abs(val7.y) >= Mathf.Abs(val7.x) && Mathf.Abs(val7.y) >= Mathf.Abs(val7.z)) ? 1 : ((Mathf.Abs(val7.z) >= Mathf.Abs(val7.x)) ? 2 : 0)); } Bounds bounds = sharedMesh.bounds; Vector3 val8 = ((Bounds)(ref bounds)).size; float meshHeight = ((Vector3)(ref val8))[vAxis]; val8 = ((Bounds)(ref bounds)).min; float footV = ((Vector3)(ref val8))[vAxis]; val8 = ((Bounds)(ref bounds)).center; float centerL = ((Vector3)(ref val8))[lAxis]; Transform val9 = val ?? rootBone ?? ((Component)character).transform; float num = ((Mathf.Abs(val9.lossyScale.y) < 1E-05f) ? 1f : val9.lossyScale.y); Vector3 val10 = ((vAxis == 0) ? Vector3.right : ((vAxis == 2) ? Vector3.forward : Vector3.up)); val8 = ((Component)mainRenderer).transform.TransformVector(val10); float magnitude = ((Vector3)(ref val8)).magnitude; float num2 = meshHeight * magnitude; float num3 = num2 / num; Func obj = delegate(Vector3? r) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) if (!r.HasValue || !(meshHeight > 1E-05f)) { return 0f; } Vector3 value = r.Value; return (((Vector3)(ref value))[vAxis] - footV) / meshHeight; }; Func func2 = delegate(Vector3? r) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) if (!r.HasValue || !(meshHeight > 1E-05f)) { return 0f; } Vector3 value = r.Value; return Mathf.Abs(((Vector3)(ref value))[lAxis] - centerL) / meshHeight; }; Vector3? arg7 = func(arg2); Vector3? arg8 = func(arg); Vector3? arg9 = func(arg3); Vector3? arg10 = func(arg5); float num4 = obj(arg7); float num5 = obj(arg8); float num6 = func2(arg9); float num7 = obj(arg9); float num8 = func2(arg10); float num9 = obj(arg10); int num10 = ((bones != null) ? bones.Length : 0); Func func3 = (float v) => v.ToString("F6", CultureInfo.InvariantCulture); using (StreamWriter streamWriter = new StreamWriter(Path.Combine(text, "mainmesh_rest.obj"))) { Mesh val11 = new Mesh(); mainRenderer.BakeMesh(val11); Vector3[] vertices = val11.vertices; Vector3[] normals = val11.normals; Vector2[] uv = val11.uv; streamWriter.WriteLine("# PEAK mesh (BakeMesh, renderer-local, current pose): " + ((Object)((Component)mainRenderer).gameObject).name); streamWriter.WriteLine($"# Vertices: {vertices.Length}"); Vector3[] array = vertices; foreach (Vector3 val12 in array) { streamWriter.WriteLine("v " + func3(val12.x) + " " + func3(val12.y) + " " + func3(val12.z)); } Vector2[] array2 = uv; foreach (Vector2 val13 in array2) { streamWriter.WriteLine("vt " + func3(val13.x) + " " + func3(val13.y)); } array = normals; foreach (Vector3 val14 in array) { streamWriter.WriteLine("vn " + func3(val14.x) + " " + func3(val14.y) + " " + func3(val14.z)); } int[] triangles = val11.triangles; for (int num12 = 0; num12 < triangles.Length; num12 += 3) { int num13 = triangles[num12] + 1; int num14 = triangles[num12 + 1] + 1; int num15 = triangles[num12 + 2] + 1; streamWriter.WriteLine($"f {num13}/{num13}/{num13} {num14}/{num14}/{num14} {num15}/{num15}/{num15}"); } Object.Destroy((Object)(object)val11); } BoneWeight[] boneWeights = sharedMesh.boneWeights; using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(Path.Combine(text, "weights.bin"), FileMode.Create))) { binaryWriter.Write(boneWeights.Length); BoneWeight[] array3 = boneWeights; for (int num11 = 0; num11 < array3.Length; num11++) { BoneWeight val15 = array3[num11]; binaryWriter.Write(((BoneWeight)(ref val15)).boneIndex0); binaryWriter.Write(((BoneWeight)(ref val15)).boneIndex1); binaryWriter.Write(((BoneWeight)(ref val15)).boneIndex2); binaryWriter.Write(((BoneWeight)(ref val15)).boneIndex3); binaryWriter.Write(((BoneWeight)(ref val15)).weight0); binaryWriter.Write(((BoneWeight)(ref val15)).weight1); binaryWriter.Write(((BoneWeight)(ref val15)).weight2); binaryWriter.Write(((BoneWeight)(ref val15)).weight3); } } using (StreamWriter streamWriter2 = new StreamWriter(Path.Combine(text, "peak_reference.json"))) { streamWriter2.WriteLine("{"); streamWriter2.WriteLine(" \"character\": \"" + ((Object)((Component)character).gameObject).name + "\","); streamWriter2.WriteLine(" \"characterHeight\": " + func3(num3) + ","); streamWriter2.WriteLine(" \"worldHeight\": " + func3(num2) + ","); streamWriter2.WriteLine(" \"meshHeight\": " + func3(meshHeight) + ","); streamWriter2.WriteLine($" \"verticalAxis\": {vAxis},"); streamWriter2.WriteLine($" \"lateralAxis\": {lAxis},"); streamWriter2.WriteLine(" \"footV\": " + func3(footV) + ","); streamWriter2.WriteLine(" \"centerL\": " + func3(centerL) + ","); streamWriter2.WriteLine(" \"anchorLossyScaleY\": " + func3(num) + ","); streamWriter2.WriteLine(" \"anchorBone\": \"" + ((Object)val9).name + "\","); streamWriter2.WriteLine(" \"boneRestProportions\": {"); streamWriter2.WriteLine(" \"headY\": " + func3(num4) + ","); streamWriter2.WriteLine(" \"torsoY\": " + func3(num5) + ","); streamWriter2.WriteLine(" \"armX\": " + func3(num6) + ","); streamWriter2.WriteLine(" \"armY\": " + func3(num7) + ","); streamWriter2.WriteLine(" \"legX\": " + func3(num8) + ","); streamWriter2.WriteLine(" \"legY\": " + func3(num9)); streamWriter2.WriteLine(" },"); streamWriter2.WriteLine(" \"vertexCount\": " + sharedMesh.vertexCount + ","); streamWriter2.WriteLine(" \"bones\": ["); for (int num16 = 0; num16 < num10; num16++) { Transform val16 = bones[num16]; if (!((Object)(object)val16 == (Object)null)) { Vector3 val17; if (bindposes == null || num16 >= bindposes.Length) { val17 = Vector3.zero; } else { Matrix4x4 inverse = ((Matrix4x4)(ref bindposes[num16])).inverse; val17 = Vector4.op_Implicit(((Matrix4x4)(ref inverse)).GetColumn(3)); } Vector3 val18 = val17; Vector3 val19 = ((Component)mainRenderer).transform.InverseTransformPoint(val16.position); string arg11 = (((Object)(object)val16.parent != (Object)null) ? ((Object)val16.parent).name : ""); string text2 = ((num16 < num10 - 1) ? "," : ""); streamWriter2.WriteLine(" {" + $"\"index\": {num16}, \"name\": \"{((Object)val16).name}\", \"parent\": \"{arg11}\", " + "\"rest_pos\": [" + func3(val18.x) + ", " + func3(val18.y) + ", " + func3(val18.z) + "], \"pose_pos\": [" + func3(val19.x) + ", " + func3(val19.y) + ", " + func3(val19.z) + "]}" + text2); } } streamWriter2.WriteLine(" ]"); streamWriter2.WriteLine("}"); } using (StreamWriter streamWriter3 = new StreamWriter(Path.Combine(_pluginDir, "peak_constants.txt"))) { streamWriter3.WriteLine("# Ground-truth from PEAK char " + ((Object)((Component)character).gameObject).name + " (F11 capture)"); streamWriter3.WriteLine("characterHeight=" + func3(num3)); streamWriter3.WriteLine("headY=" + func3(num4)); streamWriter3.WriteLine("torsoY=" + func3(num5)); streamWriter3.WriteLine("armX=" + func3(num6)); streamWriter3.WriteLine("armY=" + func3(num7)); streamWriter3.WriteLine("legX=" + func3(num8)); streamWriter3.WriteLine("legY=" + func3(num9)); } ((BaseUnityPlugin)this).Logger.LogInfo((object)("=== PEAK REFERENCE CAPTURED -> " + text + " ===")); ((BaseUnityPlugin)this).Logger.LogInfo((object)$" characterHeight(anchor-local)={num3:F4} meshHeight={meshHeight:F4} verts={sharedMesh.vertexCount} bones={num10}"); ((BaseUnityPlugin)this).Logger.LogInfo((object)$" proportions head={num4:F3} torso={num5:F3} arm=({num6:F3},{num7:F3}) leg=({num8:F3},{num9:F3})"); ((BaseUnityPlugin)this).Logger.LogInfo((object)" -> wrote peak_constants.txt (plugin will use these on next F7 reload)"); } private void HideOriginalBody(Character character) { SkinnedMeshRenderer mainRenderer = character.refs.mainRenderer; if ((Object)(object)mainRenderer != (Object)null) { ((Renderer)mainRenderer).shadowCastingMode = (ShadowCastingMode)3; } Renderer[] componentsInChildren = ((Component)character).GetComponentsInChildren(true); foreach (Renderer val in componentsInChildren) { if (((Object)((Component)val).gameObject).name.Contains("Lego_") || ((Object)((Component)val).gameObject).name.Contains("LegoMouth")) { continue; } SkinnedMeshRenderer val2 = (SkinnedMeshRenderer)(object)((val is SkinnedMeshRenderer) ? val : null); if (val2 != null) { ((Renderer)val2).shadowCastingMode = (ShadowCastingMode)3; continue; } MeshRenderer val3 = (MeshRenderer)(object)((val is MeshRenderer) ? val : null); if (val3 != null) { ((Renderer)val3).shadowCastingMode = (ShadowCastingMode)3; } } } private void CleanupLego() { if ((Object)(object)_lastCharacter != (Object)null) { RestoreOriginalBody(_lastCharacter); } Transform[] array = Object.FindObjectsByType((FindObjectsSortMode)0); foreach (Transform val in array) { if ((Object)(object)val != (Object)null && ((Object)((Component)val).gameObject).name == "LegoRoot") { Object.Destroy((Object)(object)((Component)val).gameObject); } } } private void OnDestroy() { CleanupLego(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } public class LegoBoneTracker : MonoBehaviour { public Transform targetBone; public Transform handBone; public Transform characterTransform; public float influence = 1f; public bool isHead; public bool isArm; public bool isLeg; public bool isTorso; public bool flipModel; public float legSide = 1f; public float armSide = 1f; public float maxAngle = 90f; public bool isLeftArm; public static float LeftArmBoneMag; public static float RightArmBoneMag; public static float RightArmReachWeight; private static int _emoteFrameCount; private static bool _emoteActive; private Quaternion _restLocalRotation; private Quaternion _restHandRotation; private bool _initialized; private float _smoothSwing; private float _smoothCross; private float _smoothTwist; private float _smoothCamYaw; private Vector3 _lastRootPos; private float _lastRootY; private float _legTimer; private Vector3 _restOffsetPos; private Quaternion _restOffsetRot; public float positionFollow = 1f; private bool _isClimbing; private void LateUpdate() { //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_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_0078: 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_029e: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_0128: 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_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0143: 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_0186: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)targetBone == (Object)null) { return; } Transform val = targetBone; if (!_initialized) { _restOffsetPos = val.InverseTransformPoint(((Component)this).transform.position); _restOffsetRot = Quaternion.Inverse(val.rotation) * ((Component)this).transform.rotation; _lastRootPos = (((Object)(object)val.root != (Object)null) ? val.root.position : ((Component)this).transform.position); _initialized = true; } ((Component)this).transform.position = val.TransformPoint(_restOffsetPos); Quaternion val2 = val.rotation * _restOffsetRot; if (isHead) { Camera main = Camera.main; if ((Object)(object)main != (Object)null) { float y = ((Component)main).transform.eulerAngles.y; float num = Mathf.Clamp(Mathf.DeltaAngle(val.root.eulerAngles.y, y), -15f, 15f) * 0.25f; _smoothCamYaw = Mathf.Lerp(_smoothCamYaw, num, Time.deltaTime * 4f); val2 *= Quaternion.Euler(0f, _smoothCamYaw, 0f); } } if (isLeg && (Object)(object)val.root != (Object)null && LegoSkinPlugin.LegSwing > 0.001f) { float num2 = Mathf.Max(Time.deltaTime, 0.001f); Vector3 position = val.root.position; Vector3 val3 = (position - _lastRootPos) / num2; val3.y = 0f; _lastRootPos = position; Vector3 forward = val.root.forward; forward.y = 0f; if (((Vector3)(ref forward)).sqrMagnitude > 0.0001f) { ((Vector3)(ref forward)).Normalize(); } float num3 = Vector3.Dot(val3, forward); float num4 = 0f; if (num3 > 0.3f) { _legTimer += num2 * (6f + num3 * 1.5f); float num5 = Mathf.Clamp(num3 * 9f, 0f, 32f) * LegoSkinPlugin.LegSwing; num4 = Mathf.Sin(_legTimer) * num5 * legSide; } else { _legTimer = 0f; } _smoothSwing = Mathf.Lerp(_smoothSwing, num4, num2 * 12f); val2 *= Quaternion.Euler(_smoothSwing, 0f, 0f); } ((Component)this).transform.rotation = val2; } } public class LegoStabilizer : MonoBehaviour { public Transform hipBone; public float baseYRotation = 180f; public float heightOffset; private Vector3 _lastPos; private float _smoothLean; private bool _initPos; private void LateUpdate() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0075: 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_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)hipBone == (Object)null) { return; } float y = hipBone.eulerAngles.y; float num = y + baseYRotation + LegoSkinPlugin.GlobalYawNudge; Vector3 position = hipBone.position; if (!_initPos) { _lastPos = position; _initPos = true; } float num2 = Mathf.Max(Time.deltaTime, 0.001f); Vector3 val = (position - _lastPos) / num2; _lastPos = position; float num3 = y * ((float)Math.PI / 180f); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(Mathf.Cos(num3), 0f, 0f - Mathf.Sin(num3)); float num4 = Mathf.Clamp(Vector3.Dot(val, val2) * -2f, -6f, 6f); _smoothLean = Mathf.Lerp(_smoothLean, num4, Time.deltaTime * 4f); Vector3 eulerAngles = ((Component)this).transform.eulerAngles; float num5 = Mathf.LerpAngle(eulerAngles.x, 0f, Time.deltaTime * 6f); float num6 = Mathf.LerpAngle(eulerAngles.z, _smoothLean, Time.deltaTime * 5f); float num7 = Mathf.LerpAngle(eulerAngles.y, num, Time.deltaTime * 10f); ((Component)this).transform.rotation = Quaternion.Euler(num5, num7, num6); Vector3 position2 = ((Component)this).transform.position; bool flag = (position.y - _lastPos.y) / num2 > 1.5f || position.y - position2.y > 0.3f; RaycastHit val3 = default(RaycastHit); if (Physics.Raycast(hipBone.position, Vector3.down, ref val3, 5f)) { float num8 = ((RaycastHit)(ref val3)).point.y + heightOffset; float num9 = position2.y - num8; if (!flag) { if (num9 < 0f) { position2.y = Mathf.Lerp(position2.y, num8, Time.deltaTime * 20f); } else if (num9 < 0.2f) { position2.y = Mathf.Lerp(position2.y, num8, Time.deltaTime * 14f); } } } ((Component)this).transform.position = position2; } } public class LegoHeadFader : MonoBehaviour { private Renderer[] _renderers; private void Start() { Transform parent = ((Component)this).transform.parent; _renderers = (((Object)(object)parent != (Object)null) ? ((Component)parent).GetComponentsInChildren(true) : ((Component)this).GetComponentsInChildren(true)); } private void LateUpdate() { if (_renderers == null) { return; } bool flag = LegoSkinPlugin.CamZoom + LegoSkinPlugin.CamDistOffset < 0.7f; Renderer[] renderers = _renderers; foreach (Renderer val in renderers) { if (!((Object)(object)val == (Object)null)) { val.shadowCastingMode = (ShadowCastingMode)((!flag) ? 1 : 3); val.enabled = true; } } } private void OnDestroy() { if (_renderers == null) { return; } Renderer[] renderers = _renderers; foreach (Renderer val in renderers) { if ((Object)(object)val != (Object)null) { val.shadowCastingMode = (ShadowCastingMode)1; } } } } public class LegoMouthIndicator : MonoBehaviour { public bool flipModel; public Character character; private Transform _mouthQuad; private float _smoothLevel; private Renderer _gameMouthRenderer; private Vector3 _gameMouthRestScale; private bool _gameMouthFound; private AudioClip _micClip; private string _micDevice; private const int MicWindow = 1024; private readonly float[] _micBuf = new float[1024]; private static MethodInfo _getDataMI; private void Start() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Expected O, but got Unknown //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_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_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_017e: 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_01bf: Expected O, but got Unknown //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_028e: Expected O, but got Unknown //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_02aa: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_0361: Unknown result type (might be due to invalid IL or missing references) //IL_0368: Invalid comparison between Unknown and I4 //IL_0391: Unknown result type (might be due to invalid IL or missing references) //IL_0396: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("LegoMouth"); val.transform.SetParent(((Component)this).transform, false); float num = (flipModel ? (-0.62f) : 0.62f); val.transform.localPosition = new Vector3(0f, -0.08f, num); val.transform.localRotation = (flipModel ? Quaternion.Euler(0f, 180f, 0f) : Quaternion.identity); val.transform.localScale = new Vector3(0.55f, 0.3f, 1f); _mouthQuad = val.transform; Mesh val2 = new Mesh(); val2.vertices = (Vector3[])(object)new Vector3[4] { new Vector3(-0.5f, -0.5f, 0f), new Vector3(0.5f, -0.5f, 0f), new Vector3(-0.5f, 0.5f, 0f), new Vector3(0.5f, 0.5f, 0f) }; val2.uv = (Vector2[])(object)new Vector2[4] { new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0f, 1f), new Vector2(1f, 1f) }; val2.triangles = new int[6] { 0, 2, 1, 2, 3, 1 }; val2.RecalculateNormals(); val.AddComponent().mesh = val2; int num2 = 64; Texture2D val3 = new Texture2D(num2, num2, (TextureFormat)4, false); float num3 = (float)num2 / 2f; float num4 = (float)num2 / 2f; float num5 = (float)num2 / 2f - 2f; for (int i = 0; i < num2; i++) { for (int j = 0; j < num2; j++) { float num6 = Mathf.Sqrt(((float)j - num3) * ((float)j - num3) + ((float)i - num4) * ((float)i - num4)); float num7 = Mathf.Clamp01(num5 - num6); val3.SetPixel(j, i, new Color(0.02f, 0.02f, 0.02f, num7)); } } val3.Apply(); ((Texture)val3).filterMode = (FilterMode)1; Material val4 = new Material(Shader.Find("Universal Render Pipeline/Unlit") ?? Shader.Find("Unlit/Transparent") ?? Shader.Find("Standard")); val4.mainTexture = (Texture)(object)val3; val4.SetColor("_BaseColor", Color.white); val4.color = Color.white; val4.SetFloat("_Surface", 1f); val4.SetOverrideTag("RenderType", "Transparent"); val4.SetInt("_SrcBlend", 5); val4.SetInt("_DstBlend", 10); val4.SetInt("_ZWrite", 0); val4.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); val4.SetInt("_ZTest", 8); val4.renderQueue = 3100; MeshRenderer obj = val.AddComponent(); ((Renderer)obj).material = val4; ((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0; if ((Object)(object)character != (Object)null) { Bodypart[] componentsInChildren = ((Component)character).GetComponentsInChildren(true); foreach (Bodypart val5 in componentsInChildren) { if ((int)val5.partType == 18) { _gameMouthRenderer = ((Component)val5).GetComponent(); if ((Object)(object)_gameMouthRenderer != (Object)null) { _gameMouthRestScale = ((Component)_gameMouthRenderer).transform.localScale; _gameMouthFound = true; } break; } } } try { if (Microphone.devices != null && Microphone.devices.Length != 0) { _micDevice = Microphone.devices[0]; _micClip = Microphone.Start(_micDevice, true, 1, 44100); Debug.Log((object)("[LegoSkin] Mouth mic: '" + _micDevice + "'")); } else { Debug.LogWarning((object)"[LegoSkin] No mic device for mouth VFX; using game mouth fallback"); } } catch (Exception ex) { Debug.LogWarning((object)("[LegoSkin] Mouth mic unavailable: " + ex.Message)); } } private float MicLoudness() { if ((Object)(object)_micClip == (Object)null || string.IsNullOrEmpty(_micDevice)) { return -1f; } int num = Microphone.GetPosition(_micDevice) - 1024 + 1; if (num < 0) { return 0f; } if (_getDataMI == null) { _getDataMI = typeof(AudioClip).GetMethod("GetData", new Type[2] { typeof(float[]), typeof(int) }); } if (_getDataMI == null) { return -1f; } _getDataMI.Invoke(_micClip, new object[2] { _micBuf, num }); float num2 = 0f; for (int i = 0; i < _micBuf.Length; i++) { num2 += _micBuf[i] * _micBuf[i]; } return Mathf.Sqrt(num2 / (float)_micBuf.Length); } private void LateUpdate() { //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_mouthQuad == (Object)null) { return; } float num = MicLoudness(); if (num < 0f) { num = 0f; if (_gameMouthFound && (Object)(object)_gameMouthRenderer != (Object)null) { Vector3 localScale = ((Component)_gameMouthRenderer).transform.localScale; num = Mathf.Abs(((Vector3)(ref localScale)).magnitude / Mathf.Max(((Vector3)(ref _gameMouthRestScale)).magnitude, 0.01f) - 1f); } } _smoothLevel = Mathf.Lerp(_smoothLevel, num, Time.deltaTime * 30f); float num2 = Mathf.Clamp01(_smoothLevel * LegoSkinPlugin.MouthSensitivity); _mouthQuad.localScale = new Vector3(0.55f + num2 * 0.05f, Mathf.Lerp(0.28f, 0.55f, num2), 1f); } private void OnDestroy() { if (!string.IsNullOrEmpty(_micDevice) && Microphone.IsRecording(_micDevice)) { Microphone.End(_micDevice); } } } public class LegoMouthMesh : MonoBehaviour { public Character character; public bool negateZ; public string modelsDir; public Vector3 headPivot; private Vector3[] _openVerts; private Vector3[] _closedVerts; private Mesh _mesh; private float _animTime; private float _smoothBlend = 1f; private float[] _animFrames; private float[] _animValues; private float _animDuration; private Renderer _gameMouthRenderer; private Vector3 _gameMouthRestScale; private bool _gameMouthFound; private void Start() { //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Expected O, but got Unknown //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02e9: 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) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_030f: Unknown result type (might be due to invalid IL or missing references) //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_031f: Unknown result type (might be due to invalid IL or missing references) //IL_0348: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Expected O, but got Unknown //IL_036a: Unknown result type (might be due to invalid IL or missing references) //IL_038a: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_03f9: Unknown result type (might be due to invalid IL or missing references) //IL_0400: Invalid comparison between Unknown and I4 //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0429: Unknown result type (might be due to invalid IL or missing references) //IL_042e: 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_01d2: Unknown result type (might be due to invalid IL or missing references) string path = Path.Combine(modelsDir, "mouth_open.obj"); string path2 = Path.Combine(modelsDir, "mouth_closed.obj"); if (!File.Exists(path) || !File.Exists(path2)) { return; } ObjResult objResult = ObjLoader.Load(path); ObjResult objResult2 = ObjLoader.Load(path2); if (objResult.Mesh.vertexCount == 0 || objResult2.Mesh.vertexCount == 0) { return; } _openVerts = objResult.Mesh.vertices; _closedVerts = objResult2.Mesh.vertices; if (_openVerts.Length != _closedVerts.Length) { int newSize = Mathf.Min(_openVerts.Length, _closedVerts.Length); Array.Resize(ref _openVerts, newSize); Array.Resize(ref _closedVerts, newSize); } if (negateZ) { for (int i = 0; i < _openVerts.Length; i++) { _openVerts[i] = new Vector3(_openVerts[i].x, _openVerts[i].y, 0f - _openVerts[i].z); } for (int j = 0; j < _closedVerts.Length; j++) { _closedVerts[j] = new Vector3(_closedVerts[j].x, _closedVerts[j].y, 0f - _closedVerts[j].z); } Vector3[] normals = objResult.Mesh.normals; for (int k = 0; k < normals.Length; k++) { normals[k] = new Vector3(normals[k].x, normals[k].y, 0f - normals[k].z); } objResult.Mesh.normals = normals; for (int l = 0; l < objResult.Mesh.subMeshCount; l++) { int[] triangles = objResult.Mesh.GetTriangles(l); for (int m = 0; m < triangles.Length; m += 3) { int num = triangles[m]; triangles[m] = triangles[m + 2]; triangles[m + 2] = num; } objResult.Mesh.SetTriangles(triangles, l); } } _mesh = new Mesh(); _mesh.vertices = (Vector3[])_closedVerts.Clone(); _mesh.triangles = objResult.Mesh.GetTriangles(0); _mesh.uv = objResult.Mesh.uv; _mesh.normals = objResult.Mesh.normals; _mesh.RecalculateBounds(); GameObject val = new GameObject("LegoMouthMesh"); val.transform.SetParent(((Component)this).transform, false); val.transform.localPosition = -headPivot; val.transform.localScale = Vector3.one; val.transform.localRotation = Quaternion.identity; val.AddComponent().mesh = _mesh; Material val2 = new Material(Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("Standard")); val2.SetColor("_BaseColor", new Color(0.05f, 0.05f, 0.05f, 1f)); val2.color = new Color(0.05f, 0.05f, 0.05f, 1f); val2.SetFloat("_Smoothness", 0.3f); val2.SetFloat("_Metallic", 0f); MeshRenderer obj = val.AddComponent(); ((Renderer)obj).material = val2; ((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0; LoadAnimation(); if (!((Object)(object)character != (Object)null)) { return; } Bodypart[] componentsInChildren = ((Component)character).GetComponentsInChildren(true); foreach (Bodypart val3 in componentsInChildren) { if ((int)val3.partType == 18) { _gameMouthRenderer = ((Component)val3).GetComponent(); if ((Object)(object)_gameMouthRenderer != (Object)null) { _gameMouthRestScale = ((Component)_gameMouthRenderer).transform.localScale; _gameMouthFound = true; } break; } } } private void LoadAnimation() { string path = Path.Combine(modelsDir, "mouth_anim.json"); if (!File.Exists(path)) { _animDuration = 4f; return; } try { string text = File.ReadAllText(path); float num = ParseJsonFloat(text, "fps", 24f); float num2 = ParseJsonFloat(text, "frame_start", 1f); float num3 = ParseJsonFloat(text, "frame_end", 237f); _animDuration = (num3 - num2) / num; List list = new List(); List list2 = new List(); int startIndex = 0; while ((startIndex = text.IndexOf("\"frame\"", startIndex)) >= 0) { float num4 = ParseJsonFloat(text, "frame", 0f, startIndex); int num5 = text.IndexOf("\"value\"", startIndex); if (num5 >= 0) { float item = ParseJsonFloat(text, "value", 0f, num5); list.Add((num4 - num2) / num); list2.Add(item); } startIndex = ((num5 >= 0) ? (num5 + 7) : (startIndex + 7)); } if (list.Count > 0) { _animFrames = list.ToArray(); _animValues = list2.ToArray(); } } catch (Exception) { _animDuration = 4f; } } private static float ParseJsonFloat(string json, string key, float fallback, int startIdx = 0) { string text = "\"" + key + "\""; int num = json.IndexOf(text, startIdx); if (num < 0) { return fallback; } int num2 = json.IndexOf(':', num + text.Length); if (num2 < 0) { return fallback; } int i; for (i = num2 + 1; i < json.Length && (json[i] == ' ' || json[i] == '\t' || json[i] == '\n' || json[i] == '\r'); i++) { } int num3 = i; for (; i < json.Length && (char.IsDigit(json[i]) || json[i] == '.' || json[i] == '-'); i++) { } if (float.TryParse(json.Substring(num3, i - num3), NumberStyles.Float, CultureInfo.InvariantCulture, out var result)) { return result; } return fallback; } private void LateUpdate() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_mesh == (Object)null || _openVerts == null || _closedVerts == null) { return; } bool flag = false; if (_gameMouthFound && (Object)(object)_gameMouthRenderer != (Object)null) { Vector3 localScale = ((Component)_gameMouthRenderer).transform.localScale; flag = Mathf.Abs(((Vector3)(ref localScale)).magnitude / Mathf.Max(((Vector3)(ref _gameMouthRestScale)).magnitude, 0.01f) - 1f) > 0.01f; } float num; if (flag) { _animTime += Time.deltaTime; if (_animDuration > 0f && _animTime > _animDuration) { _animTime -= _animDuration; } num = EvaluateAnimation(_animTime); } else { _animTime = 0f; num = 1f; } _smoothBlend = Mathf.Lerp(_smoothBlend, num, Time.deltaTime * 20f); Vector3[] vertices = _mesh.vertices; for (int i = 0; i < Mathf.Min(vertices.Length, _openVerts.Length); i++) { vertices[i] = Vector3.Lerp(_openVerts[i], _closedVerts[i], _smoothBlend); } _mesh.vertices = vertices; _mesh.RecalculateBounds(); } private float EvaluateAnimation(float time) { if (_animFrames == null || _animFrames.Length == 0) { return Mathf.PingPong(time * 6f, 1f); } for (int i = 0; i < _animFrames.Length - 1; i++) { if (time >= _animFrames[i] && time <= _animFrames[i + 1]) { float num = ((_animFrames[i + 1] - _animFrames[i] > 0.001f) ? ((time - _animFrames[i]) / (_animFrames[i + 1] - _animFrames[i])) : 0f); return Mathf.Lerp(_animValues[i], _animValues[i + 1], num); } } return _animValues[_animValues.Length - 1]; } } public struct PartDef { public string file; public string boneName; public Vector3 pivot; public float influence; public PartDef(string file, string boneName, Vector3 pivot, float influence) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) this.file = file; this.boneName = boneName; this.pivot = pivot; this.influence = influence; } } [HarmonyPatch(typeof(MainCameraMovement), "LateUpdate")] public static class CameraPositionPatch { private static void Postfix(MainCameraMovement __instance) { //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0162: 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_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: 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_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) if (Cursor.visible) { return; } bool value = Traverse.Create((object)__instance).Field("isSpectating").GetValue(); bool value2 = Traverse.Create((object)__instance).Field("isGodCam").GetValue(); if (value || value2) { return; } Player localPlayer = Player.localPlayer; if ((Object)(object)((localPlayer != null) ? localPlayer.character : null) == (Object)null) { return; } Character character = localPlayer.character; Camera main = Camera.main; if ((Object)(object)main == (Object)null) { return; } main.orthographic = false; Transform transform = ((Component)main).transform; float num = Mathf.Max(0f, LegoSkinPlugin.CamZoom + LegoSkinPlugin.CamDistOffset); if (num < 0.7f) { Transform headPivot = LegoSkinPlugin.HeadPivot; if ((Object)(object)headPivot != (Object)null) { float num2 = 0.12f + LegoSkinPlugin.CamHeightOffset; transform.position = headPivot.position + transform.forward * 0.45f + Vector3.up * num2; if (main.nearClipPlane > 0.02f) { main.nearClipPlane = 0.02f; } } main.fieldOfView = 75f; return; } Vector3 head = character.Head; int num3 = ~(1 << ((Component)character).gameObject.layer); float num4 = 0.3f + LegoSkinPlugin.CamHeightOffset; float num5 = 0.55f; Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(num5, num4, 0f - num); Vector3 val2 = head + transform.rotation * val; Vector3 val3 = val2 - head; float magnitude = ((Vector3)(ref val3)).magnitude; RaycastHit val4 = default(RaycastHit); if (magnitude > 0.01f && Physics.Raycast(head, ((Vector3)(ref val3)).normalized, ref val4, magnitude, num3, (QueryTriggerInteraction)1)) { val2 = ((RaycastHit)(ref val4)).point + ((RaycastHit)(ref val4)).normal * 0.2f; } transform.position = val2; main.fieldOfView = 70f; } } [HarmonyPatch(typeof(LocalPlayerRenderer), "Start")] public static class ShowLocalPlayerPatch { private static void Prefix(LocalPlayerRenderer __instance) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) if (LegoSkinPlugin.CameraEnabled) { __instance.renderMode = (ShadowCastingMode)1; } } } public class CinematicOverlay : MonoBehaviour { private Texture2D _black; private Texture2D _vignette; private Texture2D _grain; private Texture2D _desatOverlay; private float _grainTimer; private float _desatFade; private float _barFade; private void Start() { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_0015: 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_003f: Expected O, but got Unknown //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Expected O, but got Unknown //IL_0115: 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) _black = new Texture2D(1, 1); _black.SetPixel(0, 0, Color.black); _black.Apply(); int num = 256; _vignette = new Texture2D(num, num, (TextureFormat)4, false); float num2 = (float)num / 2f; float num3 = (float)num / 2f; float num4 = (float)num * 0.5f; for (int i = 0; i < num; i++) { for (int j = 0; j < num; j++) { float num5 = ((float)j - num2) / num4; float num6 = ((float)i - num3) / num4; float num7 = Mathf.Clamp01((Mathf.Sqrt(num5 * num5 + num6 * num6) - 0.5f) / 0.8f) * 0.45f; _vignette.SetPixel(j, i, new Color(0f, 0f, 0f, num7)); } } _vignette.Apply(); ((Texture)_vignette).filterMode = (FilterMode)1; _desatOverlay = new Texture2D(1, 1); _desatOverlay.SetPixel(0, 0, new Color(0.5f, 0.5f, 0.5f, 0.7f)); _desatOverlay.Apply(); RegenerateGrain(); } private void RegenerateGrain() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) int num = 64; if ((Object)(object)_grain == (Object)null) { _grain = new Texture2D(num, num, (TextureFormat)4, false); } for (int i = 0; i < num; i++) { for (int j = 0; j < num; j++) { float num2 = Random.Range(0.4f, 0.6f); float num3 = Mathf.Abs(num2 - 0.5f) * 0.06f; _grain.SetPixel(j, i, new Color(num2, num2, num2, num3)); } } _grain.Apply(); ((Texture)_grain).wrapMode = (TextureWrapMode)0; ((Texture)_grain).filterMode = (FilterMode)1; } private void OnGUI() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 //IL_009e: 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_015d: 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_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) if (LegoSkinPlugin.CameraMode == 7 && (int)Event.current.type == 7) { float num = Screen.width; float num2 = Screen.height; _desatFade = Mathf.MoveTowards(_desatFade, 1f, Time.deltaTime * 0.35f); _barFade = Mathf.MoveTowards(_barFade, 1f, Time.deltaTime * 0.5f); if (_desatFade > 0.01f) { Color val = default(Color); ((Color)(ref val))..ctor(0.5f, 0.5f, 0.5f, _desatFade * 0.65f); _desatOverlay.SetPixel(0, 0, val); _desatOverlay.Apply(); GUI.DrawTexture(new Rect(0f, 0f, num, num2), (Texture)(object)_desatOverlay); } float num3 = 2.39f; if (num / num2 < num3) { float num4 = num / num3; float num5 = (num2 - num4) * 0.5f * _barFade; Color color = GUI.color; GUI.color = new Color(0f, 0f, 0f, _barFade); GUI.DrawTexture(new Rect(0f, 0f, num, num5), (Texture)(object)_black); GUI.DrawTexture(new Rect(0f, num2 - num5, num, num5), (Texture)(object)_black); GUI.color = color; } GUI.DrawTexture(new Rect(0f, 0f, num, num2), (Texture)(object)_vignette); _grainTimer += Time.deltaTime; if (_grainTimer > 0.12f) { _grainTimer = 0f; RegenerateGrain(); } GUI.DrawTexture(new Rect(0f, 0f, num, num2), (Texture)(object)_grain); } } private void OnDestroy() { if ((Object)(object)_black != (Object)null) { Object.Destroy((Object)(object)_black); } if ((Object)(object)_vignette != (Object)null) { Object.Destroy((Object)(object)_vignette); } if ((Object)(object)_grain != (Object)null) { Object.Destroy((Object)(object)_grain); } if ((Object)(object)_desatOverlay != (Object)null) { Object.Destroy((Object)(object)_desatOverlay); } } } public class ObjResult { public Mesh Mesh; public string[] MaterialNames; } public class MtlInfo { public string TexFile; public string NormalFile; public Color KdColor = Color.white; public bool HasKdColor; } public static class ObjLoader { public static ObjResult Load(string path) { //IL_034f: Unknown result type (might be due to invalid IL or missing references) //IL_0356: Expected O, but got Unknown //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) List list = new List(); List list2 = new List(); List list3 = new List(); List list4 = new List(); List list5 = new List(); List list6 = new List(); Dictionary dictionary = new Dictionary(); List> list7 = new List>(); List list8 = new List(); List list9 = null; string[] array = File.ReadAllLines(path); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length == 0 || text[0] == '#') { continue; } string[] array2 = text.Split(new char[2] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (array2.Length == 0) { continue; } switch (array2[0]) { case "v": if (array2.Length >= 4) { list.Add(new Vector3(float.Parse(array2[1], CultureInfo.InvariantCulture), float.Parse(array2[2], CultureInfo.InvariantCulture), float.Parse(array2[3], CultureInfo.InvariantCulture))); } break; case "vt": if (array2.Length >= 3) { list2.Add(new Vector2(float.Parse(array2[1], CultureInfo.InvariantCulture), float.Parse(array2[2], CultureInfo.InvariantCulture))); } break; case "vn": if (array2.Length >= 4) { list3.Add(new Vector3(float.Parse(array2[1], CultureInfo.InvariantCulture), float.Parse(array2[2], CultureInfo.InvariantCulture), float.Parse(array2[3], CultureInfo.InvariantCulture))); } break; case "usemtl": if (array2.Length >= 2) { list9 = new List(); list7.Add(list9); list8.Add(array2[1]); } break; case "f": { if (list9 == null) { list9 = new List(); list7.Add(list9); list8.Add("default"); } List list10 = new List(); for (int j = 1; j < array2.Length; j++) { string text2 = array2[j]; if (!dictionary.TryGetValue(text2, out var value)) { value = (dictionary[text2] = list4.Count); string[] array3 = text2.Split(new char[1] { '/' }); int index = int.Parse(array3[0]) - 1; list4.Add(list[index]); if (array3.Length > 1 && array3[1].Length > 0) { int index2 = int.Parse(array3[1]) - 1; list5.Add(list2[index2]); } else { list5.Add(Vector2.zero); } if (array3.Length > 2 && array3[2].Length > 0) { int index3 = int.Parse(array3[2]) - 1; list6.Add(list3[index3]); } else { list6.Add(Vector3.up); } } list10.Add(value); } for (int k = 1; k < list10.Count - 1; k++) { list9.Add(list10[0]); list9.Add(list10[k]); list9.Add(list10[k + 1]); } break; } } } Mesh val = new Mesh(); val.indexFormat = (IndexFormat)(list4.Count > 65535); val.SetVertices(list4); val.SetUVs(0, list5); val.SetNormals(list6); val.subMeshCount = list7.Count; for (int l = 0; l < list7.Count; l++) { val.SetTriangles(list7[l], l); } val.RecalculateBounds(); return new ObjResult { Mesh = val, MaterialNames = list8.ToArray() }; } public static Dictionary ParseMtl(string mtlPath) { //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) Dictionary dictionary = new Dictionary(); if (!File.Exists(mtlPath)) { return dictionary; } string text = null; string[] array = File.ReadAllLines(mtlPath); for (int i = 0; i < array.Length; i++) { string text2 = array[i].Trim(); if (text2.StartsWith("newmtl ")) { text = text2.Substring(7).Trim(); if (!dictionary.ContainsKey(text)) { dictionary[text] = new MtlInfo(); } } else if (text2.StartsWith("map_Kd ") && text != null) { string path = text2.Substring(7).Trim(); dictionary[text].TexFile = Path.GetFileName(path); } else if (text2.StartsWith("Kd ") && text != null) { string[] array2 = text2.Split(new char[2] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (array2.Length >= 4) { float num = float.Parse(array2[1], CultureInfo.InvariantCulture); float num2 = float.Parse(array2[2], CultureInfo.InvariantCulture); float num3 = float.Parse(array2[3], CultureInfo.InvariantCulture); dictionary[text].KdColor = new Color(num, num2, num3, 1f); dictionary[text].HasKdColor = true; } } else if ((text2.StartsWith("map_Bump ") || text2.StartsWith("bump ") || text2.StartsWith("map_bump ")) && text != null) { string path2 = text2.Substring(text2.IndexOf(' ') + 1).Trim(); dictionary[text].NormalFile = Path.GetFileName(path2); } } return dictionary; } } }