using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Threading.Tasks; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Newtonsoft.Json; using UniGLTF; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.SceneManagement; using VRM; using VRMShaders; using ValheimVRM; using ValheimVRM.vrmtf; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("ValheimVRM")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.2.1.0")] [assembly: AssemblyInformationalVersion("1.2.1.0+1771301df4b3418c9bc67de43c0398df721217a7")] [assembly: AssemblyProduct("ValheimVRM")] [assembly: AssemblyTitle("ValheimVRM")] [assembly: AssemblyVersion("1.2.1.0")] public class VRMManager { private static Dictionary loaded_vrms = new Dictionary(); private static Dictionary instances = new Dictionary(); private static Dictionary> overlay_instances = new Dictionary>(); public static string ValheimVRMDir => Path.Combine(Environment.CurrentDirectory, "ValheimVRM"); public static string PlayerSettingsPath(string playerName) { return Path.Combine(ValheimVRMDir, "settings_" + playerName + ".txt"); } public static string PlayerSettingsJSONPath(string playerName) { return Path.Combine(ValheimVRMDir, playerName + ".json"); } public static string PlayerVRMPath(string playerName) { return Path.Combine(ValheimVRMDir, playerName + ".vrm"); } public static string PlayerUPFPath(string playerName) { return Path.Combine(ValheimVRMDir, playerName + ".upf"); } public static List GetLoadedModels() { return loaded_vrms.Values.ToList(); } public static VRMModel.Instance GetVRMInstance(Player ply) { if ((Object)(object)ply == (Object)null) { return null; } instances.TryGetValue(ply, out var value); return value; } public static IEnumerable GetInstancesOf(VRMModel model) { List list = overlay_instances.SelectMany((KeyValuePair> x) => x.Value.Values).ToList(); list.AddRange(instances.Values); return list.Where((VRMModel.Instance x) => x.IsValid && x.model == model); } public static VRMModel GetModelByName(string name, bool force_reload = false, VRMSettings settings_override = null, string settings_override_path = null) { VRMModel value = null; if (!force_reload && loaded_vrms.TryGetValue(name, out value)) { if (Object.op_Implicit((Object)(object)value.VisualModel)) { return value; } loaded_vrms.Remove(name); } value = new VRMModel(name); string path = PlayerSettingsJSONPath(name); string path2 = PlayerSettingsPath(name); if (settings_override != null && !File.Exists(path) && !File.Exists(path2)) { value.Settings = settings_override; value.settings_path = settings_override_path; } else if (File.Exists(path)) { value.LoadSettingsJSON(path); } else if (File.Exists(path2)) { value.LoadSettings(path2); } switch (value.Settings.ModelType) { case "upf": case "prefab": value.LoadUPF(PlayerUPFPath(name)); break; default: value.Load(PlayerVRMPath(name)); break; } value.ApplySettings(); loaded_vrms.Remove(name); loaded_vrms.Add(name, value); return value; } public static async Task GetModelByNameAsync(string name, bool force_reload = false) { VRMModel mdl2 = null; if (!force_reload && loaded_vrms.TryGetValue(name, out mdl2)) { if (Object.op_Implicit((Object)(object)mdl2.VisualModel)) { return mdl2; } loaded_vrms.Remove(name); } mdl2 = new VRMModel(name); string path = PlayerSettingsJSONPath(name); string path2 = PlayerSettingsPath(name); if (File.Exists(path)) { mdl2.LoadSettingsJSON(path); } else if (File.Exists(path2)) { mdl2.LoadSettings(path2); } await mdl2.LoadAsync(PlayerVRMPath(name)); mdl2.ApplySettings(); loaded_vrms.Remove(name); loaded_vrms.Add(name, mdl2); return mdl2; } public static VRMModel.Instance LoadAndSetupByPlayerName(Player player, string vrm_name = null, string slot = "") { try { vrm_name = vrm_name ?? VRMUtils.GetPlayerName(player); if (!string.IsNullOrEmpty(vrm_name)) { if (File.Exists(PlayerVRMPath(vrm_name)) | File.Exists(PlayerUPFPath(vrm_name))) { Debug.Log((object)("[ValheimVRM] found VRM file for " + vrm_name + ".")); VRMModel vRMModel = null; if (slot != "") { VRMModel.Instance vRMInstance = GetVRMInstance(player); vRMModel = ((vRMInstance == null) ? GetModelByName(vrm_name) : GetModelByName(vrm_name, force_reload: false, vRMInstance.model.Settings, vRMInstance.model.settings_path)); } else { vRMModel = GetModelByName(vrm_name); } if (slot != "") { if (overlay_instances.TryGetValue(player, out var value) && value.TryGetValue(slot, out var value2)) { if (Object.op_Implicit((Object)(object)value2.gameObject)) { Object.Destroy((Object)(object)value2.gameObject); } value.Remove(slot); } VRMModel.Instance instance = vRMModel.SetToPlayer(player, "VRMSlot" + slot); if (value == null) { value = new Dictionary(); overlay_instances.Add(player, value); } value.Remove(slot); value.Add(slot, instance); Debug.Log((object)("[ValheimVRM] set VRM overlay for slot " + slot + ".")); return instance; } if (instances.TryGetValue(player, out var value3)) { if (Object.op_Implicit((Object)(object)value3.gameObject)) { Object.Destroy((Object)(object)value3.gameObject); } instances.Remove(player); } VRMModel.Instance instance2 = vRMModel.SetToPlayer(player); instances.Add(player, instance2); return instance2; } Debug.Log((object)("[ValheimVRM] no VRM file for " + vrm_name + ".")); } } catch (Exception ex) { Debug.LogError((object)"Error setting VRM"); Debug.LogException(ex); } return null; } public static async Task LoadAndSetupByPlayerNameAsync(Player player, string vrm_name = null, string slot = "") { return LoadAndSetupByPlayerName(player, vrm_name, slot); } public static void RemoveFromSlotByName(Player player, string slot) { if (overlay_instances.TryGetValue(player, out var value) && value.TryGetValue(slot, out var value2)) { if (Object.op_Implicit((Object)(object)value2.gameObject)) { Object.Destroy((Object)(object)value2.gameObject); } bool flag = value.Remove(slot); Debug.Log((object)$"[ValheimVRM] removed VRM overlay from {((Object)player).name} slot {slot} result: {flag}."); } else { Debug.Log((object)("[ValheimVRM] nothing to remove from " + ((Object)player).name + " slot " + slot + ".")); } } public static void AutoEquipByHash(VRMModel.Instance base_vrm_inst, VisSlot slot, int hash) { //IL_001a: 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_0028: Invalid comparison between Unknown and I4 //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Invalid comparison between Unknown and I4 //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Invalid comparison between Unknown and I4 //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Invalid comparison between Unknown and I4 //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Invalid comparison between Unknown and I4 //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Invalid comparison between Unknown and I4 //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Invalid comparison between Unknown and I4 //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Invalid comparison between Unknown and I4 string slot2 = ((object)(VisSlot)(ref slot)).ToString(); RemoveFromSlotByName(base_vrm_inst.player, slot2); if ((int)slot == 0) { base_vrm_inst.hideLeftHand = false; } else if ((int)slot == 1) { base_vrm_inst.hideRightHand = false; } else if ((int)slot == 2) { base_vrm_inst.hideLeftBack = false; } else if ((int)slot == 3) { base_vrm_inst.hideRightBack = false; } if (hash == 0) { return; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(hash); Debug.Log((object)("[ValheimVRM] ITEM PREFAB: " + ((Object)itemPrefab).name + " ")); string value2; if ((int)slot == 2 || (int)slot == 3) { if (base_vrm_inst.model.Settings._ItemOverridesBack.TryGetValue(hash, out var value)) { LoadAndSetupByPlayerNameAsync(base_vrm_inst.player, value, slot2); if ((int)slot == 2) { base_vrm_inst.hideLeftBack = true; } else if ((int)slot == 3) { base_vrm_inst.hideRightBack = true; } } } else if (base_vrm_inst.model.Settings._ItemOverrides.TryGetValue(hash, out value2)) { LoadAndSetupByPlayerNameAsync(base_vrm_inst.player, value2, slot2); if ((int)slot == 0) { base_vrm_inst.hideLeftHand = true; } else if ((int)slot == 1) { base_vrm_inst.hideRightHand = true; } } } public static void ReloadSettingsByName(VRMModel vrm, string name) { string path = PlayerSettingsJSONPath(name); string path2 = PlayerSettingsPath(name); if (File.Exists(path)) { vrm.LoadSettingsJSON(path); } else if (File.Exists(path2)) { vrm.LoadSettings(path2); } } public static void Cleanup() { KeyValuePair>[] array = overlay_instances.ToArray(); for (int i = 0; i < array.Length; i++) { KeyValuePair> keyValuePair = array[i]; if (!Object.op_Implicit((Object)(object)keyValuePair.Key)) { overlay_instances.Remove(keyValuePair.Key); } } KeyValuePair[] array2 = instances.ToArray(); for (int i = 0; i < array2.Length; i++) { KeyValuePair keyValuePair2 = array2[i]; if (!Object.op_Implicit((Object)(object)keyValuePair2.Key)) { instances.Remove(keyValuePair2.Key); } } UnloadLooseVRMS(); } public static void UnloadLooseVRMS() { KeyValuePair[] array = loaded_vrms.ToArray(); for (int i = 0; i < array.Length; i++) { KeyValuePair keyValuePair = array[i]; if (GetInstancesOf(keyValuePair.Value).Count() <= 0) { keyValuePair.Value.Dispose(); loaded_vrms.Remove(keyValuePair.Key); Debug.Log((object)("[ValheimVRM] unloaded loose VRM " + keyValuePair.Value.Name + ".")); } } } } namespace ValheimVRM { public class AnimatorSync : MonoBehaviour { public Animator sourceAnimator; private Animator animator; private AnimatorControllerParameter[] apr; private bool filtered; public Transform HeadBone; private void OnEnable() { animator = ((Component)this).GetComponent(); apr = animator.parameters; } public void Setup(Animator animator, string head) { sourceAnimator = animator; HeadBone = UnityExtensions.FindDescendant(((Component)this).transform, head); } private void Update() { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_005f: 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_0077: Expected I4, but got Unknown //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Invalid comparison between Unknown and I4 if (!filtered) { AnimatorControllerParameter[] xparams = sourceAnimator.parameters; apr = apr.Where((AnimatorControllerParameter x) => xparams.Any((AnimatorControllerParameter y) => y.nameHash == x.nameHash)).ToArray(); filtered = true; } for (int i = 0; i < apr.Length; i++) { AnimatorControllerParameter val = apr[i]; AnimatorControllerParameterType type = val.type; switch (type - 1) { case 3: { bool @bool = sourceAnimator.GetBool(val.nameHash); animator.SetBool(val.nameHash, @bool); continue; } case 2: { int integer = sourceAnimator.GetInteger(val.nameHash); animator.SetInteger(val.nameHash, integer); continue; } case 0: { float @float = sourceAnimator.GetFloat(val.nameHash); animator.SetFloat(val.nameHash, @float); continue; } case 1: continue; } if ((int)type == 9 && sourceAnimator.GetBool(val.nameHash)) { animator.SetTrigger(val.nameHash); } } } } public class MToonColorSync : MonoBehaviour { private class MatColor { public Material mat; public Color color; public Color shadeColor; public Color emission; public bool hasColor; public bool hasShadeColor; public bool hasEmission; } private int _SunColor; private int _AmbientColor; private List matColors = new List(); private void Awake() { _SunColor = Shader.PropertyToID("_SunColor"); _AmbientColor = Shader.PropertyToID("_AmbientColor"); } public void Setup(GameObject vrm) { //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: 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_00f8: 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_00fd: Unknown result type (might be due to invalid IL or missing references) matColors.Clear(); SkinnedMeshRenderer[] componentsInChildren = vrm.GetComponentsInChildren(); for (int i = 0; i < componentsInChildren.Length; i++) { Material[] materials = ((Renderer)componentsInChildren[i]).materials; foreach (Material mat in materials) { if (!matColors.Exists((MatColor m) => (Object)(object)m.mat == (Object)(object)mat)) { matColors.Add(new MatColor { mat = mat, color = (mat.HasProperty("_Color") ? mat.GetColor("_Color") : Color.white), shadeColor = (mat.HasProperty("_ShadeColor") ? mat.GetColor("_ShadeColor") : Color.white), emission = (mat.HasProperty("_EmissionColor") ? mat.GetColor("_EmissionColor") : Color.black), hasColor = mat.HasProperty("_Color"), hasShadeColor = mat.HasProperty("_ShadeColor"), hasEmission = mat.HasProperty("_EmissionColor") }); } } } } private void Update() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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_0095: 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_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: 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_0130: Unknown result type (might be due to invalid IL or missing references) Color globalColor = Shader.GetGlobalColor(_SunColor); Color globalColor2 = Shader.GetGlobalColor(_AmbientColor); Color val = globalColor + globalColor2; if (((Color)(ref val)).maxColorComponent > 0.7f) { val /= 0.3f + ((Color)(ref val)).maxColorComponent; } foreach (MatColor matColor in matColors) { Color val2 = matColor.color * val; val2.a = matColor.color.a; if (((Color)(ref val2)).maxColorComponent > 1f) { val2 /= ((Color)(ref val2)).maxColorComponent; } Color val3 = matColor.shadeColor * val; val3.a = matColor.shadeColor.a; if (((Color)(ref val3)).maxColorComponent > 1f) { val3 /= ((Color)(ref val3)).maxColorComponent; } Color val4 = matColor.emission * ((Color)(ref val)).grayscale; if (matColor.hasColor) { matColor.mat.SetColor("_Color", val2); } if (matColor.hasShadeColor) { matColor.mat.SetColor("_ShadeColor", val3); } if (matColor.hasEmission) { matColor.mat.SetColor("_EmissionColor", val4); } } } } [DefaultExecutionOrder(int.MaxValue)] public class VRMAnimationSync : MonoBehaviour { private Animator orgAnim; private Animator vrmAnim; private HumanPoseHandler orgPose; private HumanPoseHandler vrmPose; private HumanPose hp; private VRMSettings settings; private bool ragdoll; private Vector3? adjustPos; private static List alreadyHashes = new List(); private const int FirstTime = -161139084; private const int Usually = 229373857; private const int FirstRise = -1536343465; private const int RiseUp = -805461806; private const int StartToSitDown = 890925016; private const int SittingIdle = -1544306596; private const int StandingUpFromSit = -805461806; private const int SittingChair = -1829310159; private const int SittingThrone = 1271596; private const int SittingShip = -675369009; private const int StartSleeping = 337039637; private const int Sleeping = -1603096; private const int GetUpFromBed = -496559199; private const int Crouch = -2015693266; private const int HoldingMast = -2110678410; private const int HoldingDragon = -2076823180; private static List adjustHipHashes = new List { -1829310159, 1271596, -675369009, -1603096 }; public float offset { get; set; } public void Setup(Animator orgAnim, VRMSettings settings, bool isRagdoll = false, float offset = 0f) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) this.settings = settings; this.offset = offset; this.orgAnim = orgAnim; vrmAnim = ((Component)this).GetComponent(); vrmAnim.applyRootMotion = true; vrmAnim.updateMode = orgAnim.updateMode; vrmAnim.feetPivotActive = orgAnim.feetPivotActive; vrmAnim.layersAffectMassCenter = orgAnim.layersAffectMassCenter; vrmAnim.stabilizeFeet = orgAnim.stabilizeFeet; PoseHandlerCreate(orgAnim, vrmAnim); } private void PoseHandlerCreate(Animator org, Animator vrm) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown OnDestroy(); orgPose = new HumanPoseHandler(org.avatar, ((Component)org).transform); vrmPose = new HumanPoseHandler(vrm.avatar, ((Component)vrm).transform); } private void OnDestroy() { if (orgPose != null) { orgPose.Dispose(); } if (vrmPose != null) { vrmPose.Dispose(); } } private float CalcFootSub() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) Vector3 position = orgAnim.GetBoneTransform((HumanBodyBones)6).position; Vector3 position2 = orgAnim.GetBoneTransform((HumanBodyBones)5).position; Vector3 val = (position + position2) * 0.5f; Vector3 position3 = vrmAnim.GetBoneTransform((HumanBodyBones)6).position; Vector3 position4 = vrmAnim.GetBoneTransform((HumanBodyBones)5).position; Vector3 val2 = (position3 + position4) * 0.5f; return (val - val2).y; } private Vector3 StateHashToOffset(int stateHash, out float interpSpeed) { //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: 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_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) interpSpeed = Time.deltaTime * 5f; switch (stateHash) { case -1544306596: case 890925016: return settings.SittingIdleOffset; case -1829310159: return settings.SittingOnChairOffset; case 1271596: return settings.SittingOnThroneOffset; case -675369009: return settings.SittingOnShipOffset; case -2110678410: return settings.HoldingMastOffset; case -2076823180: return settings.HoldingDragonOffset; case -1603096: return settings.SleepingOffset; default: interpSpeed = 1f; return Vector3.zero; } } private void Update() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) ((Component)vrmAnim).transform.localPosition = Vector3.zero; if (!ragdoll) { UpdateBones(); } Transform transform = ((Component)vrmAnim).transform; transform.localPosition += Vector3.up * offset; } private void LateUpdate() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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_00b6: 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_00c7: 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_00ce: 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_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_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_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_0177: 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_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0180: 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_0149: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_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_015f: 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_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: 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_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0224: 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_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) float num = 1f; ((Component)vrmAnim).transform.localPosition = Vector3.zero; _ = orgAnim.GetBoneTransform((HumanBodyBones)0).position; orgPose.GetHumanPose(ref hp); vrmPose.SetHumanPose(ref hp); AnimatorStateInfo currentAnimatorStateInfo = orgAnim.GetCurrentAnimatorStateInfo(0); int shortNameHash = ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).shortNameHash; AnimatorStateInfo nextAnimatorStateInfo = orgAnim.GetNextAnimatorStateInfo(0); int shortNameHash2 = ((AnimatorStateInfo)(ref nextAnimatorStateInfo)).shortNameHash; adjustHipHashes.Contains(shortNameHash); Transform boneTransform = vrmAnim.GetBoneTransform((HumanBodyBones)0); Transform boneTransform2 = orgAnim.GetBoneTransform((HumanBodyBones)0); Vector3 val = Vector3.zero; if (!adjustHipHashes.Contains(shortNameHash)) { Vector3 val2 = boneTransform2.position - boneTransform2.parent.position; val = val2 * num - val2; } float interpSpeed = Time.deltaTime * 5f; Vector3 val3 = StateHashToOffset(shortNameHash, out interpSpeed); if (val3 != Vector3.zero) { val += ((Component)boneTransform2).transform.rotation * val3; } Vector3 val4 = Vector3.zero; float num3; Vector3 val7; if (shortNameHash2 != 0) { if (!adjustHipHashes.Contains(shortNameHash2)) { Vector3 val5 = boneTransform2.position - boneTransform2.parent.position; val4 = val5 * num - val5; } float interpSpeed2 = Time.deltaTime * 5f; Vector3 val6 = StateHashToOffset(shortNameHash2, out interpSpeed2); if (val6 != Vector3.zero) { val4 += ((Component)boneTransform2).transform.rotation * val6; } float num2 = Mathf.Clamp01(((AnimatorStateInfo)(ref nextAnimatorStateInfo)).normalizedTime * ((AnimatorStateInfo)(ref nextAnimatorStateInfo)).length / 0.5f); num3 = Mathf.Lerp(interpSpeed, interpSpeed2, num2); val7 = Vector3.Lerp(val, val4, num2); } else { num3 = interpSpeed; val7 = val; } adjustPos = (adjustPos.HasValue ? Vector3.Lerp(adjustPos.Value, val7, num3) : val); boneTransform.position += adjustPos.Value; if (!ragdoll) { UpdateBones(); } Transform transform = ((Component)vrmAnim).transform; transform.localPosition += Vector3.up * offset; } private void UpdateBones() { for (int i = 1; i < 55; i++) { TransferBone((HumanBodyBones)i); } } private void TransferBone(HumanBodyBones humanbone) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Invalid comparison between Unknown and I4 //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Invalid comparison between Unknown and I4 //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Invalid comparison between Unknown and I4 //IL_0041: 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_003d: Invalid comparison between Unknown and I4 //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) if ((int)humanbone == 21 || (int)humanbone == 22) { return; } Transform boneTransform = orgAnim.GetBoneTransform(humanbone); Transform boneTransform2 = vrmAnim.GetBoneTransform(humanbone); if ((Object)(object)boneTransform != (Object)null && (Object)(object)boneTransform2 != (Object)null) { if ((int)humanbone == 5 || (int)humanbone == 6) { boneTransform.position = boneTransform2.position; } else { boneTransform.position = boneTransform2.position + Vector3.up * offset; } } } } public class VRMBlinkController : MonoBehaviour { private SkinnedMeshRenderer skinnedMeshRenderer; private int blendshapeid; private float next_blink; private float next_unblink; private float target_weight; private float weight; private float speed = 10f; public void Setup(SkinnedMeshRenderer target, string blendshape) { skinnedMeshRenderer = target; blendshapeid = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(blendshape); } public void Setup(SkinnedMeshRenderer target, int blendshapeid) { skinnedMeshRenderer = target; this.blendshapeid = blendshapeid; } private void LateUpdate() { float time = Time.time; if (next_blink < time) { target_weight = 1f; next_unblink = time + 0.1f; next_blink = time + Random.Range(1f, 5f); } if (next_unblink < time) { target_weight = 0f; } if (weight != target_weight) { weight = Mathf.MoveTowards(weight, target_weight, Time.deltaTime * speed); skinnedMeshRenderer.SetBlendShapeWeight(blendshapeid, weight * 100f); } } } public class VRMCharacterController : MonoBehaviour { [Serializable] public class StateMachine { public List States = new List(); public List Transitions = new List(); public string DefaultState; [NonSerialized] public State CurrentState; private Dictionary state_dict = new Dictionary(); public void Build() { foreach (State state in States) { state_dict[state.Name] = state; } foreach (Transition transition in Transitions) { State to = state_dict[transition.To]; if (transition.From == "any") { foreach (State state2 in States) { AddTransfition(state2, to, transition.Condition); } } else { State from = state_dict[transition.From]; AddTransfition(from, to, transition.Condition, transition.Reversible); } } CurrentState = state_dict[DefaultState]; } private void AddTransfition(State from, State to, string condition, bool add_reverse = false) { if (from == to) { return; } Func func = GetConditionFunc(condition); if (func == null) { Debug.LogError((object)$"[VRM StateMacine] transition init error ({from} -> {to} c:'{condition}' condition not found"); return; } from.built_transitions.Add(new Tuple, State>(func, to)); if (add_reverse) { to.built_transitions.Add(new Tuple, State>((Player x) => !func(x), from)); } } public Func GetConditionFunc(string condition) { condition = condition.Trim('(', ')', ' '); string[] array = condition.Split(new char[1] { '&' }, 2); if (array.Length == 2) { Func left2 = GetConditionFunc(array[0]); Func right2 = GetConditionFunc(array[1]); return (Player x) => left2(x) && right2(x); } string[] array2 = condition.Split(new char[1] { '|' }, 2); if (array2.Length == 2) { Func left = GetConditionFunc(array2[0]); Func right = GetConditionFunc(array2[1]); return (Player x) => left(x) || right(x); } bool flag = condition.StartsWith("!"); if (flag) { condition = condition.Substring(1); } Func func = null; switch (condition) { case "IsCrouching": func = (Player x) => ((Character)x).IsCrouching(); break; case "IsEncumbered": func = (Player x) => ((Character)x).IsEncumbered(); break; case "IsDead": func = (Player x) => ((Character)x).IsDead(); break; case "IsBlocking": func = (Player x) => ((Character)x).IsBlocking(); break; case "IsDebugFlying": func = (Player x) => ((Character)x).IsDebugFlying(); break; case "IsDrawingBow": func = (Player x) => ((Character)x).IsDrawingBow(); break; case "IsDodgeInvincible": func = (Player x) => ((Character)x).IsDodgeInvincible(); break; case "IsKnockedBack": func = (Player x) => ((Character)x).IsKnockedBack(); break; case "IsFlying": func = (Player x) => ((Character)x).IsFlying(); break; case "IsInvoking": func = (Player x) => ((MonoBehaviour)x).IsInvoking(); break; case "IsOnGround": func = (Player x) => ((Character)x).IsOnGround(); break; case "IsRiding": func = (Player x) => ((Character)x).IsRiding(); break; case "IsRunning": func = (Player x) => ((Character)x).IsRunning(); break; case "IsWallRunning": func = (Player x) => ((Character)x).IsWallRunning(); break; case "IsAttached": func = (Player x) => ((Character)x).IsAttached(); break; case "IsAttachedToShip": func = (Player x) => ((Character)x).IsAttachedToShip(); break; case "IsPVPEnabled": func = (Player x) => ((Character)x).IsPVPEnabled(); break; case "IsSafeInHome": func = (Player x) => x.IsSafeInHome(); break; case "IsSitting": func = (Player x) => ((Character)x).IsSitting(); break; case "IsSleeping": func = (Player x) => x.IsSleeping(); break; case "IsSwimming": func = (Player x) => ((Character)x).IsSwimming(); break; case "IsStaggering": func = (Player x) => ((Character)x).IsStaggering(); break; case "IsSneaking": func = (Player x) => ((Character)x).IsSneaking(); break; case "IsTeleporting": func = (Player x) => ((Character)x).IsTeleporting(); break; case "IsWalking": func = (Player x) => ((Character)x).IsWalking(); break; case "IsSensed": func = (Player x) => x.IsSensed(); break; case "InShelter": func = (Player x) => x.InShelter(); break; } if (func != null && flag) { func = (Player x) => !func(x); } return func; } public void Run(Player ply) { foreach (Tuple, State> built_transition in CurrentState.built_transitions) { if (built_transition.Item1(ply)) { Debug.Log((object)$"[VRM StateMachine] statechange {CurrentState} -> {built_transition.Item2} ()"); CurrentState = built_transition.Item2; CurrentState.Apply(ply); } } } } [Serializable] public class Transition { public string From; public string To; public string Condition; public bool Reversible; } [Serializable] public class State { public string Name; [NonSerialized] internal List, State>> built_transitions = new List, State>>(); public float? CollisionHeight { get; set; } public float? CollisionRadius { get; set; } public void Apply(Player ply) { //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) if (CollisionHeight.HasValue || CollisionRadius.HasValue) { CapsuleCollider component = ((Component)ply).GetComponent(); if (CollisionHeight.HasValue) { component.height = CollisionHeight.Value; } if (CollisionRadius.HasValue) { component.radius = CollisionRadius.Value; } component.center = new Vector3(0f, CollisionHeight.Value / 2f, 0f); ((Component)ply).GetComponent().centerOfMass = component.center; } } public override string ToString() { return Name; } } public StateMachine machine; private Player ply; private bool was_crouching; private void OnEnable() { ply = ((Component)this).GetComponent(); } private void Update() { machine?.Run(ply); } } public class VRMEyeController : MonoBehaviour { public VRMLookAtBoneApplyer lookat; public VRMLookAtHead LAh; public Transform LEYE; public Transform REYE; public float RangeYaw = 25f; public float RangePitch = 16f; public float MovementMul = 0.9f; private bool is_local_player; private float next_update; private Vector3 ort_target; private void OnEnable() { is_local_player = (Object)(object)((Component)this).GetComponentInParent() == (Object)(object)Player.m_localPlayer; } private void Update() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_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_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) _ = Time.time; Vector3 position = ((Component)Camera.main).transform.position; Matrix4x4 worldToLocalMatrix = LAh.Head.worldToLocalMatrix; Vector3 val = ((Matrix4x4)(ref worldToLocalMatrix)).MultiplyPoint(position); float num = default(float); float num2 = default(float); Matrix4x4Extensions.CalcYawPitch(Matrix4x4.identity, val - LEYE.localPosition, ref num, ref num2); num = Mathf.Clamp(num * MovementMul, 0f - RangeYaw, RangeYaw); num2 = Mathf.Clamp(num2 * MovementMul, 0f - RangePitch, RangePitch); LEYE.localRotation = Matrix4x4Extensions.YawPitchRotation(Matrix4x4.identity, num, num2); float num3 = default(float); float num4 = default(float); Matrix4x4Extensions.CalcYawPitch(Matrix4x4.identity, val - REYE.localPosition, ref num3, ref num4); num3 = Mathf.Clamp(num3 * MovementMul, 0f - RangeYaw, RangeYaw); num4 = Mathf.Clamp(num4 * MovementMul, 0f - RangePitch, RangePitch); REYE.localRotation = Matrix4x4Extensions.YawPitchRotation(Matrix4x4.identity, num3, num4); } private void ApplyRotations(float yaw, float pitch) { //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_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_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) float num; float num2; if (yaw < 0f) { num = 0f - lookat.HorizontalOuter.Map(0f - yaw); num2 = 0f - lookat.HorizontalInner.Map(0f - yaw); } else { num2 = lookat.HorizontalOuter.Map(yaw); num = lookat.HorizontalInner.Map(yaw); } pitch = ((!(pitch < 0f)) ? lookat.VerticalUp.Map(pitch) : (0f - lookat.VerticalDown.Map(0f - pitch))); if ((Object)(object)lookat.LeftEye.Transform != (Object)null && (Object)(object)lookat.RightEye.Transform != (Object)null) { Transform transform = lookat.LeftEye.Transform; Matrix4x4 initialWorldMatrix = ((OffsetOnTransform)(ref lookat.LeftEye)).InitialWorldMatrix; transform.rotation = ((Matrix4x4)(ref initialWorldMatrix)).rotation * Matrix4x4Extensions.YawPitchRotation(Matrix4x4.identity, num, pitch); Transform transform2 = lookat.RightEye.Transform; initialWorldMatrix = ((OffsetOnTransform)(ref lookat.RightEye)).InitialWorldMatrix; transform2.rotation = ((Matrix4x4)(ref initialWorldMatrix)).rotation * Matrix4x4Extensions.YawPitchRotation(Matrix4x4.identity, num2, pitch); } } } public class VRMEyePositionSync : MonoBehaviour { private Transform vrmEye; private Transform orgEye; public void Setup(Transform vrmEye) { this.vrmEye = vrmEye; orgEye = ((Character)((Component)this).GetComponent()).m_eye; } private void Update() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) Vector3 position = orgEye.position; position.y = vrmEye.position.y; orgEye.position = position; } } public static class FieldAccess { public static FieldRef m_helmetItemInstance = AccessTools.FieldRefAccess("m_helmetItemInstance"); public static FieldRef m_hairItemInstance = AccessTools.FieldRefAccess("m_hairItemInstance"); public static FieldRef m_beardItemInstance = AccessTools.FieldRefAccess("m_beardItemInstance"); public static FieldRef m_rightItemInstance = AccessTools.FieldRefAccess("m_rightItemInstance"); public static FieldRef m_leftItemInstance = AccessTools.FieldRefAccess("m_leftItemInstance"); public static FieldRef m_rightBackItemInstance = AccessTools.FieldRefAccess("m_rightBackItemInstance"); public static FieldRef m_leftBackItemInstance = AccessTools.FieldRefAccess("m_leftBackItemInstance"); public static FieldRef> m_chestItemInstances = AccessTools.FieldRefAccess>("m_chestItemInstances"); public static FieldRef> m_shoulderItemInstances = AccessTools.FieldRefAccess>("m_shoulderItemInstances"); public static FieldRef> m_utilityItemInstances = AccessTools.FieldRefAccess>("m_utilityItemInstances"); public static FieldRef> m_legItemInstances = AccessTools.FieldRefAccess>("m_legItemInstances"); public static FieldRef m_originalLocalRef = AccessTools.FieldRefAccess("m_originalLocalRef"); public static FieldRef m_profileIndex = AccessTools.FieldRefAccess("m_profileIndex"); public static FieldRef> m_profiles = AccessTools.FieldRefAccess>("m_profiles"); public static FieldRef m_nview = AccessTools.FieldRefAccess("m_nview"); public static FieldRef m_zanim = AccessTools.FieldRefAccess("m_zanim"); public static FieldRef m_animator = AccessTools.FieldRefAccess("m_animator"); public static FieldRef m_maxAirAltitude = AccessTools.FieldRefAccess("m_maxAirAltitude"); } internal class JSONExt { public static Vector3JsonConverter v3j; static JSONExt() { v3j = new Vector3JsonConverter(); } } public class Vector3JsonConverter : JsonConverter { public override bool CanRead => true; public override bool CanConvert(Type objectType) { return objectType == typeof(Vector3); } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) Vector3 val = (Vector3)value; writer.WriteStartArray(); writer.WriteValue(val.x); writer.WriteValue(val.y); writer.WriteValue(val.z); writer.WriteEndArray(); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) return (object)new Vector3((float)reader.ReadAsDouble().Value, (float)reader.ReadAsDouble().Value, (float)reader.ReadAsDouble().Value); } } public class NullableConverter : JsonConverter where T : struct { public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { T? val = (T?)value; if (val.HasValue) { writer.WriteValue((object)val.Value); } } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.Value == null) { return default(T); } return reader.Value; } public override bool CanConvert(Type objectType) { return objectType == typeof(T?); } } [BepInPlugin("com.jh.plugins.valheimvrmex", "ValheimVRM_EX", "1.0.0.0")] [BepInProcess("valheim.exe")] public class MainPlugin : BaseUnityPlugin { public const string PluginGuid = "com.jh.plugins.valheimvrmex"; public const string PluginName = "ValheimVRM_EX"; public const string PluginVersion = "1.0.0.0"; public static ConfigEntry ToggleFlight; public static ConfigEntry Ability1; public static StatusEffect ShadowFormEffect; private void Awake() { //IL_0005: 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_0052: Unknown result type (might be due to invalid IL or missing references) new Harmony("com.jh.plugins.valheimvrmex").PatchAll(); VRMShaders.Initialize(); ToggleFlight = ((BaseUnityPlugin)this).Config.Bind("Input", "ToggleFlight", new KeyboardShortcut((KeyCode)102, Array.Empty()), (ConfigDescription)null); Ability1 = ((BaseUnityPlugin)this).Config.Bind("Input", "ActivateAbility1", new KeyboardShortcut((KeyCode)103, Array.Empty()), (ConfigDescription)null); ShadowFormEffect = (StatusEffect)(object)ScriptableObject.CreateInstance(); ((Object)ShadowFormEffect).name = "ShadowForm"; ShadowFormEffect.m_name = "Shadow form"; ShadowFormEffect.m_startMessage = "Shadow form"; ShadowFormEffect.m_stopMessage = "Normal form"; } } [HarmonyPatch(typeof(ObjectDB), "Awake")] internal static class Patch_ObjectDB_Init { [HarmonyPostfix] private static void Postfix(ObjectDB __instance) { RegisterStatusEffect(MainPlugin.ShadowFormEffect); void RegisterStatusEffect(StatusEffect statusEffect) { if (statusEffect != null && !Object.op_Implicit((Object)(object)__instance.GetStatusEffect(StringExtensionMethods.GetStableHashCode(((Object)statusEffect).name)))) { __instance.m_StatusEffects.Add(statusEffect); } } } } [HarmonyPatch(typeof(Character), "GetHeadPoint")] internal static class Patch_Character_GetHeadPoint { [HarmonyPostfix] private static bool Prefix(Character __instance, ref Vector3 __result) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_0071: 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) if (!__instance.IsPlayer()) { return true; } VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance((Player)__instance); if (vRMInstance != null && Object.op_Implicit((Object)(object)vRMInstance.gameObject)) { Animator componentInChildren = vRMInstance.gameObject.GetComponentInChildren(); if ((Object)(object)componentInChildren == (Object)null) { return true; } if (!componentInChildren.isHuman) { AnimatorSync component = vRMInstance.gameObject.GetComponent(); if ((Object)(object)component != (Object)null && Object.op_Implicit((Object)(object)component.HeadBone)) { __result = component.HeadBone.position; return false; } } Transform boneTransform = componentInChildren.GetBoneTransform((HumanBodyBones)10); if ((Object)(object)boneTransform == (Object)null) { return true; } __result = boneTransform.position; return false; } return true; } } [HarmonyPatch(typeof(Character), "SetVisible")] internal static class Patch_Character_SetVisible { [HarmonyPostfix] private static void Postfix(Character __instance, bool visible) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) if (!__instance.IsPlayer()) { return; } VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance((Player)__instance); if (vRMInstance != null && Object.op_Implicit((Object)(object)vRMInstance.gameObject)) { LODGroup component = vRMInstance.gameObject.GetComponent(); if (visible) { component.localReferencePoint = FieldAccess.m_originalLocalRef.Invoke(__instance); } else { component.localReferencePoint = new Vector3(999999f, 999999f, 999999f); } } } } [HarmonyPatch(typeof(Character), "UpdateMotion")] internal static class Patch_Character_UpdateMotion { [HarmonyPostfix] private static void Postfix(Character __instance, float dt) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_00da: 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_00e3: 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_009b: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) if (!__instance.IsPlayer()) { return; } Player val = (Player)__instance; VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance(val); if (vRMInstance == null) { return; } bool flag = !InventoryGui.IsVisible() && !Menu.IsVisible() && !GameCamera.InFreeFly() && !Minimap.IsOpen() && !Hud.IsPieceSelectionVisible() && !StoreGui.IsVisible() && !Console.IsVisible() && !Chat.instance.HasFocus() && !PlayerCustomizaton.IsBarberGuiVisible() && !Hud.InRadial(); VRMSettings settings = vRMInstance.model.Settings; KeyboardShortcut value; if (settings.CanFly && (Object)(object)Player.m_localPlayer == (Object)(object)__instance && flag) { value = MainPlugin.ToggleFlight.Value; if (ZInput.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey, true)) { Debug.Log((object)$"[DEBUG] toggle flight {__instance}"); if (__instance.IsFlying()) { __instance.Land(); } else { __instance.TakeOff(); } } } if (flag) { value = MainPlugin.Ability1.Value; if (ZInput.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey, true) && !string.IsNullOrWhiteSpace(settings.Ability1)) { int stableHashCode = StringExtensionMethods.GetStableHashCode(settings.Ability1.Trim()); ZRoutedRpc instance = ZRoutedRpc.instance; if (instance != null) { instance.InvokeRoutedRPC(ZNetView.Everybody, "RPC_AbilityCast", new object[3] { val.GetPlayerID(), stableHashCode, false }); } } } if (settings.NoFallDamage && !__instance.IsFlying()) { FieldAccess.m_maxAirAltitude.Invoke(__instance) = ((Component)__instance).transform.position.y; } if (__instance.IsFlying()) { if (__instance.IsRunning()) { __instance.UseStamina(dt * settings.FastFlightStaminaUsage * Game.m_moveStaminaRate, false); } else { __instance.UseStamina(dt * settings.FlightStaminaUsage * Game.m_moveStaminaRate, false); } } } public static void RPC_AbilityCast(long sender, long pid, int hash, bool end) { Player player = Player.GetPlayer(pid); if ((Object)(object)player == (Object)null) { return; } SEMan sEMan = ((Character)player).GetSEMan(); if (sEMan.HaveStatusEffect(hash)) { if (sEMan.GetStatusEffect(hash).GetDuration() > 4f) { sEMan.RemoveStatusEffect(hash, false); } } else { StatusEffect statusEffect = ObjectDB.instance.GetStatusEffect(hash); sEMan.AddStatusEffect(statusEffect, false, 0, 0f); } } } [HarmonyPatch(typeof(Game), "Start")] public static class GameStartPatch { private static void Prefix() { ZRoutedRpc.instance.Register("RPC_AbilityCast", (Action)Patch_Character_UpdateMotion.RPC_AbilityCast); } } [HarmonyPatch(typeof(Character), "UpdateWalking")] internal static class Patch_Character_UpdateWalking { private static readonly int s_forwardSpeed = ZSyncAnimation.GetHash("forward_speed"); private static readonly int s_sidewaySpeed = ZSyncAnimation.GetHash("sideway_speed"); [HarmonyPostfix] private static void Postfix(Character __instance, float dt) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown if (__instance.IsPlayer()) { VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance((Player)__instance); if (vRMInstance != null && vRMInstance.speed_coeff != 1f) { ZSyncAnimation obj = FieldAccess.m_zanim.Invoke(__instance); Animator obj2 = FieldAccess.m_animator.Invoke(__instance); float @float = obj2.GetFloat(s_forwardSpeed); float float2 = obj2.GetFloat(s_sidewaySpeed); obj.SetFloat(s_forwardSpeed, @float / vRMInstance.speed_coeff); obj.SetFloat(s_sidewaySpeed, float2 / vRMInstance.speed_coeff); } } } } [HarmonyPatch(typeof(Humanoid), "OnRagdollCreated")] internal static class Patch_Humanoid_OnRagdollCreated { [HarmonyPostfix] private static void Postfix(Humanoid __instance, Ragdoll ragdoll) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown if (!((Character)__instance).IsPlayer()) { return; } VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance((Player)__instance); if (vRMInstance != null) { SkinnedMeshRenderer[] componentsInChildren = ((Component)ragdoll).GetComponentsInChildren(); foreach (SkinnedMeshRenderer obj in componentsInChildren) { ((Renderer)obj).forceRenderingOff = true; obj.updateWhenOffscreen = true; } Animator val = ((Component)ragdoll).gameObject.AddComponent(); val.keepAnimatorStateOnDisable = true; val.cullingMode = (AnimatorCullingMode)0; Animator val2 = FieldAccess.m_animator.Invoke((Character)(Player)__instance); val.avatar = val2.avatar; if (Object.op_Implicit((Object)(object)vRMInstance.gameObject)) { vRMInstance.gameObject.transform.SetParent(((Component)ragdoll).transform, false); vRMInstance.gameObject.GetComponent().Setup(val, vRMInstance.model.Settings, isRagdoll: true); } } } } [HarmonyPatch(typeof(VisEquipment), "SetUtilityEquipped")] internal static class Patch_Humanoid_SetUtilityEquipped { [HarmonyPostfix] private static void Postfix(VisEquipment __instance, int hash) { if (__instance.m_isPlayer) { VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance(((Component)__instance).GetComponent()); if (vRMInstance != null && vRMInstance.m_currentUtilityItemHash != hash) { Debug.Log((object)$"[ValheimVRM] [SetUtilityEquipped] itemHash: {vRMInstance.m_currentUtilityItemHash} -> {hash} "); VRMManager.AutoEquipByHash(vRMInstance, (VisSlot)8, hash); vRMInstance.m_currentUtilityItemHash = hash; } } } } [HarmonyPatch(typeof(Player), "Start")] internal static class Patch_Player_Awake { private static Dictionary vrmDic = new Dictionary(); [HarmonyPostfix] private static void Postfix(Player __instance) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) VRMCommands.Trigger(); Scene scene = ((Component)__instance).gameObject.scene; bool num = ((Scene)(ref scene)).name == "start"; string target_vrm = null; if (num) { VRMManager.Cleanup(); } else if ((Object)(object)Player.m_localPlayer != (Object)(object)__instance) { ((MonoBehaviour)__instance).StartCoroutine(WaitForForm(__instance)); } string text = __instance.m_customData.TryGetOrDefault("vrm_form"); if (!string.IsNullOrWhiteSpace(text)) { target_vrm = text; Debug.Log((object)$"saved VRM form found {text} for {__instance}"); } if ((Object)(object)Player.m_localPlayer != (Object)(object)__instance) { VRMTF.DoTransformLocal(__instance, target_vrm, 0f); } else { VRMTF.DoTransform(__instance, target_vrm, 0f); } } private static IEnumerator WaitForForm(Player __instance) { yield return (object)new WaitForEndOfFrame(); bool is_received = false; __instance.GetPlayerID(); while (!is_received) { ZNetView obj = FieldAccess.m_nview.Invoke(__instance); object obj2; if (obj == null) { obj2 = null; } else { ZDO zDO = obj.GetZDO(); obj2 = ((zDO != null) ? zDO.GetString(VRMTFController.vrm_form, (string)null) : null); } string text = (string)obj2; if (!string.IsNullOrWhiteSpace(text)) { is_received = true; Debug.Log((object)$"serverside VRM form received {text} for {__instance}"); VRMTF.DoTransformLocal(__instance, text, 0f); } yield return (object)new WaitForEndOfFrame(); } } [Obsolete] private static GameObject ImportVRM(string path, float scale) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) try { VRMImporterContext val = new VRMImporterContext(new VRMData(new GlbFileParser(path).Parse()), (IReadOnlyDictionary)null, (ITextureDeserializer)null, (IMaterialDescriptorGenerator)null, true); try { RuntimeGltfInstance obj = ImporterContextExtensions.Load((ImporterContext)(object)val); obj.ShowMeshes(); Transform transform = obj.Root.transform; transform.localScale *= scale; Debug.Log((object)"[ValheimVRM] VRM loading successful"); Debug.Log((object)("[ValheimVRM] VRM file path: " + path)); return obj.Root; } finally { ((IDisposable)val)?.Dispose(); } } catch (Exception ex) { Debug.LogError((object)ex); } return null; } } [HarmonyPatch(typeof(Player), "GetHoverName")] internal static class Patch_Player_GetPlayerName { [HarmonyPostfix] private static bool Prefix(Player __instance, ref string __result) { VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance(__instance); if (vRMInstance != null && vRMInstance.model.Settings.DisplayName != null) { __result = vRMInstance.model.Settings.DisplayName; return true; } return false; } } [HarmonyPatch(typeof(Player), "OnDeath")] internal static class Patch_Player_OnDeath { [HarmonyPostfix] private static void Postfix(Player __instance) { VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance(__instance); if (vRMInstance != null && vRMInstance.model.Settings.FixCameraHeight) { Object.Destroy((Object)(object)((Component)__instance).GetComponent()); } } } [HarmonyPatch(typeof(Player), "SetControls")] internal static class Patch_Player_SetControls { [HarmonyPostfix] private static void Postfix(Player __instance, Vector3 movedir, bool attack, bool attackHold, bool secondaryAttack, bool secondaryAttackHold, bool block, bool blockHold, bool jump, bool crouch, bool run, bool autoRun, bool dodge = false) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_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_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) if (((Character)__instance).IsPlayer() && ((Character)__instance).IsFlying()) { Vector3 lookDir = ((Character)__instance).GetLookDir(); ((Vector3)(ref lookDir)).Normalize(); Vector3 moveDir = movedir.z * lookDir + movedir.x * Vector3.Cross(Vector3.up, lookDir); ((Character)__instance).SetMoveDir(moveDir); if (__instance.GetStamina() <= 0f) { ((Character)__instance).Land(); } } } } [HarmonyPatch(typeof(Shader))] [HarmonyPatch("Find")] internal static class Patch_Shader_Find { private static bool Prefix(ref Shader __result, string name) { if (VRMShaders.Shaders.TryGetValue(name, out var value)) { __result = value; return false; } return true; } } [HarmonyPatch(typeof(VisEquipment), "SetChestEquipped")] internal static class Patch_VisEquipment_SetChestEquipped { [HarmonyPostfix] private static void Postfix(VisEquipment __instance, int hash) { if (__instance.m_isPlayer) { VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance(((Component)__instance).GetComponent()); if (vRMInstance != null && vRMInstance.m_currentChestItemHash != hash) { Debug.Log((object)$"[ValheimVRM] [SetChestEquipped] itemHash: {vRMInstance.m_currentChestItemHash} -> {hash} "); VRMManager.AutoEquipByHash(vRMInstance, (VisSlot)4, hash); vRMInstance.m_currentChestItemHash = hash; } } } } [HarmonyPatch(typeof(VisEquipment), "SetHelmetEquipped")] internal static class Patch_VisEquipment_SetHelmetEquipped { [HarmonyPostfix] private static void Postfix(VisEquipment __instance, int hash) { if (__instance.m_isPlayer) { VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance(((Component)__instance).GetComponent()); if (vRMInstance != null && vRMInstance.m_currentHelmetItemHash != hash) { Debug.Log((object)$"[ValheimVRM] [SetHelmetEquipped] itemHash: {vRMInstance.m_currentHelmetItemHash} -> {hash} "); VRMManager.AutoEquipByHash(vRMInstance, (VisSlot)6, hash); vRMInstance.m_currentHelmetItemHash = hash; } } } } [HarmonyPatch(typeof(VisEquipment), "SetLeftBackItem")] internal static class Patch_VisEquipment_SetLeftBackItem { [HarmonyPostfix] private static void Postfix(VisEquipment __instance, string name, int variant) { if (!__instance.m_isPlayer) { return; } VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance(((Component)__instance).GetComponent()); if (vRMInstance != null) { int num = ((!string.IsNullOrEmpty(name)) ? StringExtensionMethods.GetStableHashCode(name) : 0); if (vRMInstance.m_currentLeftBackItemHash != num) { Debug.Log((object)$"[ValheimVRM] [SetLeftBackItem] itemHash: {vRMInstance.m_currentLeftBackItemHash} -> {num} VARIANT:{variant}"); VRMManager.AutoEquipByHash(vRMInstance, (VisSlot)2, num); vRMInstance.m_currentLeftBackItemHash = num; } } } } [HarmonyPatch(typeof(VisEquipment), "SetLeftHandEquipped")] internal static class Patch_VisEquipment_SetLeftHandEquipped { [HarmonyPostfix] private static void Postfix(VisEquipment __instance, int hash, int variant) { if (__instance.m_isPlayer) { VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance(((Component)__instance).GetComponent()); if (vRMInstance != null && vRMInstance.m_currentLeftItemHash != hash) { Debug.Log((object)$"[ValheimVRM] [SetLeftHandEquipped] itemHash: {vRMInstance.m_currentLeftItemHash} -> {hash} VARIANT:{variant}"); VRMManager.AutoEquipByHash(vRMInstance, (VisSlot)0, hash); vRMInstance.m_currentLeftItemHash = hash; } } } } [HarmonyPatch(typeof(VisEquipment), "SetLegEquipped")] internal static class Patch_VisEquipment_SetLegEquipped { [HarmonyPostfix] private static void Postfix(VisEquipment __instance, int hash) { if (__instance.m_isPlayer) { VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance(((Component)__instance).GetComponent()); if (vRMInstance != null && vRMInstance.m_currentLegItemHash != hash) { Debug.Log((object)$"[ValheimVRM] [SetLegEquipped] itemHash: {vRMInstance.m_currentLegItemHash} -> {hash} "); VRMManager.AutoEquipByHash(vRMInstance, (VisSlot)5, hash); vRMInstance.m_currentLegItemHash = hash; } } } } [HarmonyPatch(typeof(VisEquipment), "SetRightBackItem")] internal static class Patch_VisEquipment_SetRightBackItem { [HarmonyPostfix] private static void Postfix(VisEquipment __instance, string name) { if (!__instance.m_isPlayer) { return; } VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance(((Component)__instance).GetComponent()); if (vRMInstance != null) { int num = ((!string.IsNullOrEmpty(name)) ? StringExtensionMethods.GetStableHashCode(name) : 0); if (vRMInstance.m_currentRightBackItemHash != num) { Debug.Log((object)$"[ValheimVRM] [SetRightBackItem] itemHash: {vRMInstance.m_currentRightBackItemHash} -> {num} "); VRMManager.AutoEquipByHash(vRMInstance, (VisSlot)1, num); vRMInstance.m_currentRightBackItemHash = num; } } } } [HarmonyPatch(typeof(VisEquipment), "SetRightHandEquipped")] internal static class Patch_VisEquipment_SetRightHandEquipped { [HarmonyPostfix] private static void Postfix(VisEquipment __instance, int hash) { if (__instance.m_isPlayer) { VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance(((Component)__instance).GetComponent()); if (vRMInstance != null && vRMInstance.m_currentRightItemHash != hash) { Debug.Log((object)$"[ValheimVRM] [SetRightHandEquipped] itemHash: {vRMInstance.m_currentRightItemHash} -> {hash} "); VRMManager.AutoEquipByHash(vRMInstance, (VisSlot)1, hash); vRMInstance.m_currentRightItemHash = hash; } } } } [HarmonyPatch(typeof(VisEquipment), "SetShoulderEquipped")] internal static class Patch_VisEquipment_SetShoulderEquipped { [HarmonyPostfix] private static void Postfix(VisEquipment __instance, int hash) { if (__instance.m_isPlayer) { VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance(((Component)__instance).GetComponent()); if (vRMInstance != null && vRMInstance.m_currentShoulderItemHash != hash) { Debug.Log((object)$"[ValheimVRM] [SetShoulderEquipped] itemHash: {vRMInstance.m_currentShoulderItemHash} -> {hash} "); VRMManager.AutoEquipByHash(vRMInstance, (VisSlot)7, hash); vRMInstance.m_currentShoulderItemHash = hash; } } } } [HarmonyPatch(typeof(VisEquipment), "UpdateLodgroup")] internal static class Patch_VisEquipment_UpdateLodgroup { [HarmonyPostfix] private static void Postfix(VisEquipment __instance) { //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) if (!__instance.m_isPlayer) { return; } VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance(((Component)__instance).GetComponent()); if (vRMInstance != null) { GameObject gameObject = FieldAccess.m_hairItemInstance.Invoke(__instance); GameObject gameObject2 = FieldAccess.m_beardItemInstance.Invoke(__instance); List gameObjects = FieldAccess.m_chestItemInstances.Invoke(__instance); List gameObjects2 = FieldAccess.m_legItemInstances.Invoke(__instance); List gameObjects3 = FieldAccess.m_shoulderItemInstances.Invoke(__instance); List gameObjects4 = FieldAccess.m_utilityItemInstances.Invoke(__instance); GameObject gameObject3 = FieldAccess.m_helmetItemInstance.Invoke(__instance); GameObject val = FieldAccess.m_leftItemInstance.Invoke(__instance); GameObject val2 = FieldAccess.m_rightItemInstance.Invoke(__instance); vRMInstance.HairVisibility.SetVisible(gameObject, !vRMInstance.model.Settings.HideHair); vRMInstance.BeardVisibility.SetVisible(gameObject2, !vRMInstance.model.Settings.HideBeard); vRMInstance.ChestVisibility.SetVisible(gameObjects, !vRMInstance.model.Settings.HideChest); vRMInstance.LegsVisibility.SetVisible(gameObjects2, !vRMInstance.model.Settings.HideLegs); vRMInstance.ShoulderVisibility.SetVisible(gameObjects3, !vRMInstance.model.Settings.HideShoulder); vRMInstance.UtilityVisibility.SetVisible(gameObjects4, !vRMInstance.model.Settings.HideUtility); vRMInstance.HelmetVisibility.SetVisible(gameObject3, !vRMInstance.model.Settings.HideHelmet); if ((Object)(object)val != (Object)null) { val.transform.localPosition = vRMInstance.model.Settings.LeftHandEuqipPos; vRMInstance.LeftItemVisibility.SetVisible(val, !vRMInstance.hideLeftHand); } if ((Object)(object)val2 != (Object)null) { val2.transform.localPosition = vRMInstance.model.Settings.RightHandEuqipPos; vRMInstance.LeftItemVisibility.SetVisible(val2, !vRMInstance.hideRightHand); } GameObject val3 = FieldAccess.m_rightBackItemInstance.Invoke(__instance); if ((Object)(object)val3 != (Object)null) { val3.transform.localPosition = vRMInstance.model.Settings.RightHandBackItemPos / 100f; vRMInstance.RightBackItemVisibility.SetVisible(val3, !vRMInstance.hideRightBack); } GameObject val4 = FieldAccess.m_leftBackItemInstance.Invoke(__instance); if ((Object)(object)val4 != (Object)null) { val4.transform.localPosition = vRMInstance.model.Settings.LeftHandBackItemPos / 100f; vRMInstance.LeftBackItemVisibility.SetVisible(val4, !vRMInstance.hideLeftBack); } } } } internal static class Settings { private static Dictionary playerSettings = new Dictionary(); public static string ValheimVRMDir => Path.Combine(Environment.CurrentDirectory, "ValheimVRM"); public static string PlayerSettingsPath(string playerName) { return Path.Combine(ValheimVRMDir, "settings_" + playerName + ".txt"); } public static VRMSettings Get(string playerName) { playerSettings.TryGetValue(playerName, out var value); return value; } public static void AddSettings(string playerName, string[] lines) { //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) playerSettings[playerName] = new VRMSettings { EnablePlayerFade = ReadBool(ReadSettings(lines, "EnablePlayerFade"), defaultValue: true), FixCameraHeight = ReadBool(ReadSettings(lines, "FixCameraHeight"), defaultValue: true), UseMToonShader = ReadBool(ReadSettings(lines, "UseMToonShader")), ModelScale = ReadFloat(ReadSettings(lines, "ModelScale"), 1.1f), ModelOffsetY = ReadFloat(ReadSettings(lines, "ModelOffsetY")), ModelBrightness = ReadFloat(ReadSettings(lines, "ModelBrightness"), 0.8f), SpringBoneStiffness = ReadFloat(ReadSettings(lines, "SpringBoneStiffness"), 1f), SpringBoneGravityPower = ReadFloat(ReadSettings(lines, "SpringBoneGravityPower"), 1f), LeftHandEuqipPos = ReadVector3(ReadSettings(lines, "LeftHandEuqipPos"), Vector3.zero), RightHandEuqipPos = ReadVector3(ReadSettings(lines, "RightHandEuqipPos"), Vector3.zero), LeftHandBackItemPos = ReadVector3(ReadSettings(lines, "LeftHandBackItemPos"), Vector3.zero), RightHandBackItemPos = ReadVector3(ReadSettings(lines, "RightHandBackItemPos"), Vector3.zero) }; } public static bool AddSettingsFromFile(string playerName) { string path = PlayerSettingsPath(playerName); if (File.Exists(path)) { string[] lines = File.ReadAllLines(path); AddSettings(playerName, lines); return true; } return false; } public static bool ContainsSettings(string playerName) { return playerSettings.ContainsKey(playerName); } public static string ReadSettings(string[] lines, string key) { string text = null; try { foreach (string text2 in lines) { try { if (text2.Length <= 1 || !(text2.Substring(0, 2) == "//")) { string[] array = text2.Split(new char[1] { '=' }); if (array.Length == 2 && array[0] == key) { text = array[1]; } } } catch { } } } catch { } if (text == null) { Debug.LogWarning((object)("[ValheimVRM] Setting item not found: " + key)); } return text; } public static int ReadInt(string value, int defaultValue = 0, bool debugLog = false) { if (value == null) { return defaultValue; } int result = defaultValue; if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out result)) { return result; } return defaultValue; } public static float ReadFloat(string value, float defaultValue = 0f, bool debugLog = false) { if (value == null) { return defaultValue; } float result = defaultValue; if (float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out result)) { return result; } return defaultValue; } public static bool ReadBool(string value, bool defaultValue = false, bool debugLog = false) { if (value == null) { return defaultValue; } bool result = defaultValue; if (bool.TryParse(value, out result)) { return result; } return defaultValue; } public static Vector3 ReadVector3(string value, Vector3 defaultValue = default(Vector3), bool debugLog = false) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) if (value == null) { return defaultValue; } string[] array = value.Trim().Trim(' ', '(', ')').Split(new char[1] { ',' }); if (array.Length == 3) { try { Vector3 result = default(Vector3); result.x = float.Parse(array[0], CultureInfo.InvariantCulture); result.y = float.Parse(array[1], CultureInfo.InvariantCulture); result.z = float.Parse(array[2], CultureInfo.InvariantCulture); return result; } catch (FormatException ex) { Debug.LogError((object)ex); } } return defaultValue; } } public abstract class SettingsBase { public class Field { public Type type; public FieldInfo info; public object default_value; } public static Dictionary PopulateFieldInfo() { Dictionary dictionary = new Dictionary(); VRMSettings obj = Activator.CreateInstance(); FieldInfo[] fields = typeof(VRMSettings).GetFields(); foreach (FieldInfo fieldInfo in fields) { if (fieldInfo.GetCustomAttribute(typeof(NonSerializedAttribute)) == null) { dictionary.Add(fieldInfo.Name, new Field { type = fieldInfo.FieldType, info = fieldInfo, default_value = fieldInfo.GetValue(obj) }); } } return dictionary; } public abstract Dictionary Load(Dictionary settings); protected void LoadValues(Dictionary settings, Dictionary old_values, Dictionary public_fields) { //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_0246: 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_02fe: Unknown result type (might be due to invalid IL or missing references) foreach (KeyValuePair public_field in public_fields) { if (!settings.TryGetValue(public_field.Key, out var value)) { continue; } object value2 = public_field.Value.info.GetValue(this); object obj = value2; try { if (public_field.Value.type == typeof(string)) { obj = value; } else if (public_field.Value.type == typeof(float)) { obj = float.Parse(value, CultureInfo.InvariantCulture); } else if (public_field.Value.type == typeof(int)) { obj = int.Parse(value, CultureInfo.InvariantCulture); } else if (public_field.Value.type == typeof(bool)) { obj = bool.Parse(value); } else if (public_field.Value.type.IsEnum) { obj = Enum.Parse(public_field.Value.type, value); } else if (public_field.Value.type == typeof(Vector2)) { string[] array = value.Trim().Trim(' ', '(', ')').Split(new char[1] { ',' }); Vector2 val = default(Vector2); val.x = float.Parse(array[0], CultureInfo.InvariantCulture); val.y = float.Parse(array[1], CultureInfo.InvariantCulture); obj = val; } else if (public_field.Value.type == typeof(Vector3)) { string[] array2 = value.Trim().Trim(' ', '(', ')').Split(new char[1] { ',' }); Vector3 val2 = default(Vector3); val2.x = float.Parse(array2[0], CultureInfo.InvariantCulture); val2.y = float.Parse(array2[1], CultureInfo.InvariantCulture); val2.z = float.Parse(array2[2], CultureInfo.InvariantCulture); obj = val2; } else { if (!(public_field.Value.type == typeof(Vector4))) { throw new NotSupportedException(); } string[] array3 = value.Trim().Trim(' ', '(', ')').Split(new char[1] { ',' }); Vector4 val3 = default(Vector4); val3.x = float.Parse(array3[0], CultureInfo.InvariantCulture); val3.y = float.Parse(array3[1], CultureInfo.InvariantCulture); val3.z = float.Parse(array3[2], CultureInfo.InvariantCulture); val3.w = float.Parse(array3[3], CultureInfo.InvariantCulture); obj = val3; } } catch (Exception ex) { Debug.LogError((object)$"[ValheimVRM] Error reading setting {public_field.Key} = {public_field.Value} ({public_field.Value.type}) {ex.Message}"); } if (obj != value2) { public_field.Value.info.SetValue(this, obj); old_values.Add(public_field.Key, value2); } } } } public class ShadowForm : StatusEffect { public override void Setup(Character character) { ((StatusEffect)this).Setup(character); RuntimeGltfInstance componentInChildren = ((Component)base.m_character).GetComponentInChildren(); if ((Object)(object)componentInChildren != (Object)null) { FieldAccess.m_animator.Invoke(character).SetBool("shadow_form", true); ((MonoBehaviour)base.m_character).StartCoroutine(delayedactions(character, componentInChildren)); } } private IEnumerator delayedactions(Character character, RuntimeGltfInstance vrm) { yield return (object)new WaitForSecondsRealtime(1f); SkinnedMeshRenderer[] componentsInChildren = ((Component)vrm).GetComponentsInChildren(); for (int i = 0; i < componentsInChildren.Length; i++) { ((Renderer)componentsInChildren[i]).shadowCastingMode = (ShadowCastingMode)3; } FieldAccess.m_animator.Invoke(character).SetBool("shadow_form", false); } public override void Stop() { ((StatusEffect)this).Stop(); RuntimeGltfInstance componentInChildren = ((Component)base.m_character).GetComponentInChildren(); if ((Object)(object)componentInChildren != (Object)null) { FieldAccess.m_animator.Invoke(base.m_character).SetBool("shadow_form", true); ((MonoBehaviour)base.m_character).StartCoroutine(delayedactions2(base.m_character, componentInChildren)); } } private IEnumerator delayedactions2(Character character, RuntimeGltfInstance vrm) { yield return (object)new WaitForSecondsRealtime(1f); SkinnedMeshRenderer[] componentsInChildren = ((Component)vrm).GetComponentsInChildren(); for (int i = 0; i < componentsInChildren.Length; i++) { ((Renderer)componentsInChildren[i]).shadowCastingMode = (ShadowCastingMode)1; } FieldAccess.m_animator.Invoke(character).SetBool("shadow_form", false); } } public static class VRMUtils { public static T RequireComponent(this GameObject gameObject) where T : Component { T val = gameObject.GetComponent(); if ((Object)(object)val == (Object)null) { val = gameObject.AddComponent(); } return val; } public static string GetPlayerName(Player player) { string text = null; if ((Object)(object)Game.instance != (Object)null) { text = player.GetPlayerName(); if (text == "" || text == "...") { text = Game.instance.GetPlayerProfile().GetName(); } } else { int num = FieldAccess.m_profileIndex.Invoke(FejdStartup.instance); List list = FieldAccess.m_profiles.Invoke(FejdStartup.instance); if (num >= 0 && num < list.Count) { text = list[num].GetName(); } } return text; } public static void Set(this Dictionary dict, T1 key, T2 value) { if (value == null) { dict.Remove(key); } else if (dict.ContainsKey(key)) { dict[key] = value; } else { dict.Add(key, value); } } public static T2 TryGetOrDefault(this Dictionary dict, T1 key, T2 default_value = default(T2)) { if (dict.TryGetValue(key, out var value)) { return value; } return default_value; } public static void DrawWireSphere(Vector3 center, float radius, Color color, float duration, int quality = 3) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_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_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_0073: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) quality = Mathf.Clamp(quality, 1, 10); int num = quality << 2; int num2 = quality << 3; int num3 = num >> 1; float num4 = 360f / (float)num2; float num5 = 180f / (float)num; for (int i = 0; i < num; i++) { Vector3 val = Vector3.forward * radius; val = Quaternion.AngleAxis(num5 * (float)(i - num3), Vector3.right) * val; for (int j = 0; j < num2; j++) { Vector3 val2 = Quaternion.AngleAxis(num4, Vector3.up) * val; Debug.DrawLine(val + center, val2 + center, color, duration); val = val2; } } for (int k = 0; k < num; k++) { Vector3 val = Vector3.forward * radius; val = Quaternion.AngleAxis(num5 * (float)(k - num3), Vector3.up) * val; Vector3 val3 = Quaternion.AngleAxis(90f, Vector3.up) * val; for (int l = 0; l < num2; l++) { Vector3 val2 = Quaternion.AngleAxis(num4, val3) * val; Debug.DrawLine(val + center, val2 + center, color, duration); val = val2; } } } public static AssetBundle RequireBundle(string path) { AssetBundle val = AssetBundle.GetAllLoadedAssetBundles().FirstOrDefault((Func)((AssetBundle x) => ((Object)x).name == path)); if ((Object)(object)val == (Object)null) { val = AssetBundle.LoadFromFile(Path.Combine(VRMManager.ValheimVRMDir, path)); } Debug.Log((object)("asset bundle name '" + ((Object)val).name + "'")); return val; } } public static class VRMCommands { public static readonly ConsoleCommand ReloadSettings = new ConsoleCommand("vrm_reload_settings", "reload VRM settings for your character", (ConsoleEvent)delegate(ConsoleEventArgs args) { if ((Object)(object)Player.m_localPlayer == (Object)null) { args.Context.AddString("[ValheimVRM] No local player found!"); } else { VRMModel.Instance vRMInstance = VRMManager.GetVRMInstance(Player.m_localPlayer); if (vRMInstance != null) { string playerName = VRMUtils.GetPlayerName(Player.m_localPlayer); VRMManager.ReloadSettingsByName(vRMInstance.model, playerName); args.Context.AddString("[ValheimVRM] Settings for " + playerName + " were reloaded"); } } }, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); public static readonly ConsoleCommand ReloadSettingsAll = new ConsoleCommand("vrm_reload_settings_all", "reload all loaded VRM settings", (ConsoleEvent)delegate(ConsoleEventArgs args) { foreach (VRMModel loadedModel in VRMManager.GetLoadedModels()) { if (loadedModel.ReloadSettings()) { args.Context.AddString("[ValheimVRM] Settings for " + loadedModel.Name + " were reloaded"); } } }, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); public static readonly ConsoleCommand ReloadAll = new ConsoleCommand("vrm_reload_all", "reload all models and settings", (ConsoleEvent)delegate { _reloadall(); }, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); public static readonly ConsoleCommand ChangeModel = new ConsoleCommand("vrm_change_model", "change character model (local)", (ConsoleEvent)delegate(ConsoleEventArgs args) { if ((Object)(object)Player.m_localPlayer == (Object)null) { args.Context.AddString("[ValheimVRM] No local player found!"); } else if (args.Args.Length < 2) { args.Context.AddString("[ValheimVRM] first argument should be VRM name!"); } else { args.Context.AddString("[ValheimVRM] set VRM '" + args.Args[1] + "'."); VRMManager.LoadAndSetupByPlayerNameAsync(Player.m_localPlayer, args.Args[1]); } }, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); public static readonly ConsoleCommand DebugPrintPlayer = new ConsoleCommand("vrm_print_player", "print player object hierarchy", (ConsoleEvent)delegate(ConsoleEventArgs args) { if ((Object)(object)Player.m_localPlayer == (Object)null) { args.Context.AddString("[ValheimVRM] No local player found!"); } else { Print(args.Context, ((Component)Player.m_localPlayer).gameObject); } }, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); public static readonly ConsoleCommand TransformTo = new ConsoleCommand("vrm_transform", "change character model (NOT LOCAL)", (ConsoleEvent)delegate(ConsoleEventArgs args) { if ((Object)(object)Player.m_localPlayer == (Object)null) { args.Context.AddString("[ValheimVRM] No local player found!"); } else if (args.Args.Length < 2) { args.Context.AddString("[ValheimVRM] first argument should be VRM name!"); } else { args.Context.AddString("[ValheimVRM] transform to VRM '" + args.Args[1] + "'."); VRMTF.DoTransform(Player.m_localPlayer, args.Args[1]); } }, true, false, false, true, false, (ConsoleOptionsFetcher)null, false, false, false); public static readonly ConsoleCommand ListPlayers = new ConsoleCommand("vrm_list_players", " ", (ConsoleEvent)delegate(ConsoleEventArgs args) { foreach (Player allPlayer in Player.GetAllPlayers()) { args.Context.AddString($"player {allPlayer.GetPlayerName()} {allPlayer.GetPlayerID()}"); } }, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); public static readonly ConsoleCommand GetZValue = new ConsoleCommand("vrm_get_value_str", " ", (ConsoleEvent)delegate(ConsoleEventArgs args) { if (args.Args.Length < 3) { args.Context.AddString("[ValheimVRM] first argument should be Player ID!"); args.Context.AddString("[ValheimVRM] second argument should be variable name!"); } else { long num = long.Parse(args.Args[1]); Player player = Player.GetPlayer(num); if ((Object)(object)player == (Object)null) { args.Context.AddString($"[ValheimVRM] player with id: {num} not found!"); } else { ZNetView obj = FieldAccess.m_nview.Invoke(player); ZDO val3 = ((obj != null) ? obj.GetZDO() : null); if (val3 == null) { args.Context.AddString("[ValheimVRM] player zdo does not exist!"); } else { string @string = val3.GetString(StringExtensionMethods.GetStableHashCode(args.Args[2]), ""); args.Context.AddString("[ValheimVRM] RESULT: " + args.Args[2] + " = '" + @string + "'"); } } } }, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); public static readonly ConsoleCommand ListAnims = new ConsoleCommand("vrm_list_animations", " ", (ConsoleEvent)delegate { AnimationClip[] animationClips = FieldAccess.m_animator.Invoke((Character)(object)Player.m_localPlayer).runtimeAnimatorController.animationClips; foreach (AnimationClip val2 in animationClips) { Debug.Log((object)$"[A] '{((Object)val2).name}' loop:{((Motion)val2).isLooping} id:{((Object)val2).GetInstanceID()} hash:{((object)val2).GetHashCode()}"); } }, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); public static readonly ConsoleCommand CurAnim = new ConsoleCommand("vrm_current_animation", " ", (ConsoleEvent)delegate { Animator val = FieldAccess.m_animator.Invoke((Character)(object)Player.m_localPlayer); for (int i = 0; i < val.layerCount; i++) { AnimatorClipInfo[] currentAnimatorClipInfo = val.GetCurrentAnimatorClipInfo(i); Debug.Log((object)$"[{i}] '{val.GetLayerName(i)}' w:{val.GetLayerWeight(i)} "); for (int j = 0; j < currentAnimatorClipInfo.Length; j++) { AnimationClip clip = ((AnimatorClipInfo)(ref currentAnimatorClipInfo[j])).clip; if ((Object)(object)clip != (Object)null) { Debug.Log((object)$" >'{((Object)clip).name}' loop:{((Motion)clip).isLooping} id:{((Object)clip).GetInstanceID()}"); } } } }, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); private static async Task _reloadall() { _ = 1; try { foreach (VRMModel i in VRMManager.GetLoadedModels()) { IEnumerable insts = VRMManager.GetInstancesOf(i); int c = 0; foreach (VRMModel.Instance item in insts) { item.Remove(); c++; } if (c > 0) { Stopwatch sw2 = Stopwatch.StartNew(); Debug.Log((object)("[ValheimVRM] Reloading " + i.Name)); if (await i.ReloadModel()) { Debug.Log((object)$"[ValheimVRM][{sw2.ElapsedMilliseconds}ms] Model loaded"); i.ReloadSettings(no_reapply_values: true); Debug.Log((object)$"[ValheimVRM][{sw2.ElapsedMilliseconds}ms] Settings loaded"); i.ApplySettings(); Debug.Log((object)$"[ValheimVRM][{sw2.ElapsedMilliseconds}ms] Settings applied"); } foreach (VRMModel.Instance item2 in insts) { item2.Reset(); } Debug.Log((object)$"[ValheimVRM][{sw2.ElapsedMilliseconds}ms] {i.Name} were reloaded, instances affected: {c}"); sw2.Stop(); } else { Stopwatch sw2 = Stopwatch.StartNew(); Debug.Log((object)("[ValheimVRM] Reloading " + i.Name)); if (await i.ReloadModel()) { Debug.Log((object)$"[ValheimVRM][{sw2.ElapsedMilliseconds}ms] Model loaded"); i.ReloadSettings(no_reapply_values: true); Debug.Log((object)$"[ValheimVRM][{sw2.ElapsedMilliseconds}ms] Settings loaded"); i.ApplySettings(); Debug.Log((object)$"[ValheimVRM][{sw2.ElapsedMilliseconds}ms] Settings applied"); } Debug.Log((object)$"[ValheimVRM][{sw2.ElapsedMilliseconds}ms] {i.Name} were reloaded, no instances affected"); sw2.Stop(); } } } catch (Exception ex) { Debug.LogError((object)("[ValheimVRM] " + ex.Message + " " + ex.StackTrace)); } } private static void Print(Terminal context, GameObject gameObject, int tabstop = 0) { string text = new string(' ', tabstop * 2); Debug.Log((object)(text + "go " + ((Object)gameObject).name)); Component[] components = gameObject.GetComponents(); foreach (Component val in components) { if (!(val is Transform) && !(val is RectTransform)) { Debug.Log((object)$"{text} -com {((object)val).GetType()}"); } } Transform transform = gameObject.transform; for (int j = 0; j < transform.childCount; j++) { Transform child = transform.GetChild(j); Print(context, ((Component)child).gameObject, tabstop + 1); } } public static int Trigger() { return 1; } } public class VRMModel { public enum Type { VRM, UnityPrefab } public class Instance { public bool is_overlay; public string slot; public bool hideRightHand; public bool hideLeftHand; public bool hideRightBack; public bool hideLeftBack; public int m_currentLeftItemHash; public int m_currentRightItemHash; public int m_currentChestItemHash; public int m_currentLegItemHash; public int m_currentHelmetItemHash; public int m_currentShoulderItemHash; public int m_currentBeardItemHash; public int m_currentHairItemHash; public int m_currentUtilityItemHash; public int m_currentLeftBackItemHash; public int m_currentRightBackItemHash; public CachedVisibility HairVisibility = new CachedVisibility(); public CachedVisibility BeardVisibility = new CachedVisibility(); public CachedVisibility ChestVisibility = new CachedVisibility(); public CachedVisibility LegsVisibility = new CachedVisibility(); public CachedVisibility ShoulderVisibility = new CachedVisibility(); public CachedVisibility UtilityVisibility = new CachedVisibility(); public CachedVisibility HelmetVisibility = new CachedVisibility(); public CachedVisibility LeftItemVisibility = new CachedVisibility(); public CachedVisibility RightItemVisibility = new CachedVisibility(); public CachedVisibility LeftBackItemVisibility = new CachedVisibility(); public CachedVisibility RightBackItemVisibility = new CachedVisibility(); public float speed_coeff = 1f; public bool IsValid => Object.op_Implicit((Object)(object)player); public Player player { get; private set; } public VRMModel model { get; private set; } public GameObject gameObject { get; private set; } public Instance(Player player, VRMModel model, GameObject gameObject) { this.player = player; this.model = model; this.gameObject = gameObject; } public void Reset() { RemoveFromPlayer(player, slot); gameObject = model.CreateInstance(player, slot); } public void Remove() { RemoveFromPlayer(player, slot); gameObject = null; } public void SetVisible(bool enabled) { if (Object.op_Implicit((Object)(object)gameObject)) { Renderer[] componentsInChildren = gameObject.GetComponentsInChildren(); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = enabled; } } } } public class CachedVisibility { private GameObject root; private List roots = new List(); public bool state; private List _cachedrenderers = new List(); public void SetVisible(GameObject gameObject, bool new_state) { if ((Object)(object)gameObject == (Object)null) { return; } if ((Object)(object)gameObject != (Object)(object)root) { root = gameObject; _cachedrenderers.Clear(); MeshRenderer[] componentsInChildren = gameObject.GetComponentsInChildren(); foreach (MeshRenderer val in componentsInChildren) { _cachedrenderers.Add((Renderer)(object)val); ((Renderer)val).enabled = new_state; } SkinnedMeshRenderer[] componentsInChildren2 = gameObject.GetComponentsInChildren(); foreach (SkinnedMeshRenderer val2 in componentsInChildren2) { _cachedrenderers.Add((Renderer)(object)val2); ((Renderer)val2).enabled = new_state; } state = new_state; } else { if (state == new_state) { return; } state = new_state; foreach (Renderer cachedrenderer in _cachedrenderers) { cachedrenderer.enabled = new_state; } } } public void SetVisible(List gameObjects, bool new_state) { if (gameObjects == null) { return; } if (IsRootsDiffer(gameObjects)) { roots.Clear(); roots.AddRange(gameObjects); _cachedrenderers.Clear(); foreach (GameObject gameObject in gameObjects) { MeshRenderer[] componentsInChildren = gameObject.GetComponentsInChildren(); foreach (MeshRenderer val in componentsInChildren) { _cachedrenderers.Add((Renderer)(object)val); ((Renderer)val).enabled = new_state; } SkinnedMeshRenderer[] componentsInChildren2 = gameObject.GetComponentsInChildren(); foreach (SkinnedMeshRenderer val2 in componentsInChildren2) { _cachedrenderers.Add((Renderer)(object)val2); ((Renderer)val2).enabled = new_state; } } state = new_state; } else { if (state == new_state) { return; } state = new_state; foreach (Renderer cachedrenderer in _cachedrenderers) { cachedrenderer.enabled = new_state; } } } private bool IsRootsDiffer(List gameObjects) { if (roots.Count != gameObjects.Count) { return true; } for (int i = 0; i < roots.Count; i++) { if ((Object)(object)roots[i] != (Object)(object)gameObjects[i]) { return true; } } return false; } } public Type ModelType; public string settings_path; public string model_path; public string left_eye_path; public string right_eye_path; private static RuntimeAnimatorController _the_original_player_animcontroller; public GameObject VisualModel { get; private set; } public string Name { get; private set; } public VRMSettings Settings { get; set; } public VRMModel(string name) { Name = name; } ~VRMModel() { Dispose(); } public void Dispose() { if ((Object)(object)VisualModel != (Object)null) { Object.Destroy((Object)(object)VisualModel); } } public void Load(string path) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) try { model_path = path; GltfData data = new GlbFileParser(path).Parse(); LoadData(data); Debug.Log((object)"[ValheimVRM] VRM loading successful (file)"); Debug.Log((object)("[ValheimVRM] VRM file path: " + path)); } catch (Exception ex) { Debug.LogError((object)ex); } } public async Task LoadAsync(string path) { try { model_path = path; GltfData data = new GlbFileParser(path).Parse(); Debug.Log((object)"[ValheimVRM] VRM async load started"); await LoadDataAsync(data); Debug.Log((object)"[ValheimVRM] VRM loading successful (file)"); Debug.Log((object)("[ValheimVRM] VRM file path: " + path)); } catch (Exception ex) { Debug.LogError((object)ex); } } public void Load(byte[] binary) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) try { model_path = null; GltfData data = new GlbBinaryParser(binary, Name).Parse(); LoadData(data); Debug.Log((object)"[ValheimVRM] VRM loading successful (memory)"); } catch (Exception ex) { Debug.LogError((object)ex); } } private void LoadData(GltfData data) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown VRMData val = new VRMData(data); RemoveEyes(val); VRMImporterContext val2 = new VRMImporterContext(val, (IReadOnlyDictionary)null, (ITextureDeserializer)null, (IMaterialDescriptorGenerator)null, true); try { RuntimeGltfInstance val3 = ImporterContextExtensions.Load((ImporterContext)(object)val2); val3.ShowMeshes(); Dispose(); foreach (SkinnedMeshRenderer skinnedMeshRenderer in val3.SkinnedMeshRenderers) { skinnedMeshRenderer.updateWhenOffscreen = true; } VisualModel = val3.Root; ModelType = Type.VRM; } finally { ((IDisposable)val2)?.Dispose(); } } private async Task LoadDataAsync(GltfData data) { VRMData val = new VRMData(data); RemoveEyes(val); VRMImporterContext context = new VRMImporterContext(val, (IReadOnlyDictionary)null, (ITextureDeserializer)null, (IMaterialDescriptorGenerator)null, true); try { RuntimeOnlyAwaitCaller val2 = new RuntimeOnlyAwaitCaller(1f); RuntimeGltfInstance val3 = await ((ImporterContext)context).LoadAsync((IAwaitCaller)(object)val2, (Func)null); val3.ShowMeshes(); Dispose(); foreach (SkinnedMeshRenderer skinnedMeshRenderer in val3.SkinnedMeshRenderers) { skinnedMeshRenderer.updateWhenOffscreen = true; } VisualModel = val3.Root; } finally { ((IDisposable)context)?.Dispose(); } } public void LoadUPF(string path) { GameObject val = VRMUtils.RequireBundle(path).LoadAsset(Settings.PrefabName); SkinnedMeshRenderer[] componentsInChildren = val.GetComponentsInChildren(); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].updateWhenOffscreen = true; } VisualModel = val; ModelType = Type.UnityPrefab; } private void RemoveEyes(VRMData vrm) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Invalid comparison between Unknown and I4 //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Invalid comparison between Unknown and I4 if (vrm == null || vrm.VrmExtension == null || vrm.VrmExtension.humanoid == null) { return; } glTF_VRM_HumanoidBone[] array = vrm.VrmExtension.humanoid.humanBones.ToArray(); foreach (glTF_VRM_HumanoidBone val in array) { if ((int)val.vrmBone == 21) { left_eye_path = vrm.Data.GLTF.nodes[val.node].name; vrm.VrmExtension.humanoid.humanBones.Remove(val); Debug.Log((object)("[VRMM] found left eye '" + left_eye_path + "' removing...")); } else if ((int)val.vrmBone == 22) { right_eye_path = vrm.Data.GLTF.nodes[val.node].name; vrm.VrmExtension.humanoid.humanBones.Remove(val); Debug.Log((object)("[VRMM] found right eye '" + right_eye_path + "' removing...")); } } } public async Task ReloadModel() { if (model_path != null) { await LoadAsync(model_path); return true; } return false; } public void LoadSettings(string path, bool no_reload = false) { if (File.Exists(path)) { settings_path = path; string[] lines = File.ReadAllLines(path); LoadSettingsData(lines, no_reload); } } public void LoadSettingsJSON(string path, bool no_reload = false) { if (File.Exists(path)) { settings_path = path; VRMSettings vRMSettings = JsonConvert.DeserializeObject(File.ReadAllText(path)); if (!no_reload) { vRMSettings.ApplyChanges(this, vRMSettings.GetChanges(Settings)); } Settings = vRMSettings; } } private void LoadSettingsData(string[] lines, bool no_reload = false) { Dictionary dictionary = new Dictionary(); foreach (string text in lines) { if (!string.IsNullOrWhiteSpace(text) && !text.Trim().StartsWith("//")) { string[] array = text.Split(new char[1] { '=' }); if (array.Length == 2) { dictionary.Add(array[0].Trim(), array[1].Trim()); } } } bool flag = Settings != null && (Object)(object)VisualModel != (Object)null; VRMSettings vRMSettings = new VRMSettings(); Dictionary old_values = vRMSettings.Load(dictionary); Settings = vRMSettings; if (!no_reload && flag) { vRMSettings.ApplyChanges(this, old_values); } } public bool ReloadSettings(bool no_reapply_values = false) { if (settings_path != null) { if (settings_path.ToLower().EndsWith(".json")) { LoadSettingsJSON(settings_path, no_reapply_values); } else { LoadSettings(settings_path, no_reapply_values); } return true; } return false; } public void ApplySettings() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0168: 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_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_0304: 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_01e1: Unknown result type (might be due to invalid IL or missing references) Transform transform = VisualModel.transform; transform.localScale *= Settings.ModelScale; float modelBrightness = Settings.ModelBrightness; List list = new List(); SkinnedMeshRenderer[] componentsInChildren = VisualModel.GetComponentsInChildren(); foreach (SkinnedMeshRenderer val in componentsInChildren) { Material[] materials = ((Renderer)val).materials; foreach (Material item in materials) { if (!list.Contains(item)) { list.Add(item); } } Bounds localBounds = val.localBounds; ((Bounds)(ref localBounds)).Expand(2f); } MeshRenderer[] componentsInChildren2 = VisualModel.GetComponentsInChildren(); for (int i = 0; i < componentsInChildren2.Length; i++) { Material[] materials = ((Renderer)componentsInChildren2[i]).materials; foreach (Material item2 in materials) { if (!list.Contains(item2)) { list.Add(item2); } } } if (Settings.UseMToonShader) { foreach (Material item3 in list) { if (item3.HasProperty("_Color")) { Color color = item3.GetColor("_Color"); color.r *= modelBrightness; color.g *= modelBrightness; color.b *= modelBrightness; item3.SetColor("_Color", color); } } } else { Shader val2 = Shader.Find("Custom/Player"); foreach (Material item4 in list) { if (!((Object)(object)item4.shader == (Object)(object)val2)) { Color val3 = (item4.HasProperty("_Color") ? item4.GetColor("_Color") : Color.white); val3.r *= modelBrightness; val3.g *= modelBrightness; val3.b *= modelBrightness; Texture2D val4 = (Texture2D)(item4.HasProperty("_MainTex") ? /*isinst with value type is only supported in some contexts*/: null); Texture val5 = (item4.HasProperty("_BumpMap") ? item4.GetTexture("_BumpMap") : null); item4.shader = val2; item4.SetTexture("_MainTex", (Texture)null); item4.SetTexture("_SkinBumpMap", (Texture)null); item4.SetTexture("_LegsTex", (Texture)(object)val4); item4.SetTexture("_LegsBumpMap", val5); item4.SetFloat("_Glossiness", 0.2f); item4.SetFloat("_MetalGlossiness", 0f); } } } LODGroup val6 = VisualModel.AddComponent(); Renderer[] componentsInChildren3 = (Renderer[])(object)VisualModel.GetComponentsInChildren(); LOD val7 = default(LOD); ((LOD)(ref val7))..ctor(0.1f, componentsInChildren3); if (Settings.EnablePlayerFade) { val6.SetLODs((LOD[])(object)new LOD[1] { val7 }); } val6.RecalculateBounds(); VisualModel.SetActive(false); } public static void RemoveFromPlayer(Player player, string slot = "VRMInstance") { Transform val = ((Component)((Component)player).GetComponentInChildren()).transform.parent.Find(slot); if (!((Object)(object)val != (Object)null)) { return; } Object.Destroy((Object)(object)((Component)val).gameObject); if (slot == "VRMInstance") { VRMEyePositionSync component = ((Component)player).gameObject.GetComponent(); if (Object.op_Implicit((Object)(object)component)) { Object.Destroy((Object)(object)component); } } } public Instance SetToPlayer(Player player, string slot = "VRMInstance") { //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) GameObject val = CreateInstance(player, slot); Instance instance = new Instance(player, this, val); instance.slot = slot; instance.is_overlay = slot != "VRMInstance"; if (Settings.LegAffectsSpeed && !instance.is_overlay) { float num = 1f; float num2 = 1f; Animator obj = FieldAccess.m_animator.Invoke((Character)(object)player); Transform boneTransform = obj.GetBoneTransform((HumanBodyBones)0); Transform boneTransform2 = obj.GetBoneTransform((HumanBodyBones)5); Vector3 val2 = boneTransform.position - boneTransform2.position; num = ((Vector3)(ref val2)).magnitude; Debug.Log((object)$"TEST: original model leg length: {num}"); Animator component = val.GetComponent(); Transform boneTransform3 = component.GetBoneTransform((HumanBodyBones)0); Transform boneTransform4 = component.GetBoneTransform((HumanBodyBones)5); val2 = boneTransform3.position - boneTransform4.position; num2 = ((Vector3)(ref val2)).magnitude; Debug.Log((object)$"TEST: vrm model leg length: {num2}"); if (num > 0f && num2 > 0f) { float num3 = num2 / num; ((Character)player).m_speed = ((Character)player).m_speed * num3; ((Character)player).m_crouchSpeed = ((Character)player).m_crouchSpeed * num3; ((Character)player).m_runSpeed = ((Character)player).m_runSpeed * num3; ((Character)player).m_walkSpeed = ((Character)player).m_walkSpeed * num3; instance.speed_coeff = num3; Debug.Log((object)$"TEST: calc speed coeff: {num3}"); } } if (!instance.is_overlay) { player.m_baseHP = Settings.BaseHP; player.m_baseStamina = Settings.BaseStamina; ((Character)player).m_swimSpeed = Settings.SwimSpeed; ((Character)player).m_swimDepth = Settings.SwimDepth; ((Character)player).m_jumpStaminaUsage = Settings.JumpStaminaUsage; ((Character)player).m_flySlowSpeed = Settings.FlySlowSpeed; ((Character)player).m_flyFastSpeed = Settings.FlyFastSpeed; ((Character)player).m_flyTurnSpeed = Settings.FlyTurnSpeed; player.m_runStaminaDrain = Settings.RunStaminaDrain; player.m_sneakStaminaDrain = Settings.SneakStaminaDrain; player.m_swimStaminaDrainMinSkill = Settings.SwimStaminaDrainMinSkill; player.m_swimStaminaDrainMaxSkill = Settings.SwimStaminaDrainMaxSkill; player.m_dodgeStaminaUsage = Settings.DodgeStaminaUsage; player.m_weightStaminaFactor = Settings.WeightStaminaFactor; player.m_maxCarryWeight = Settings.MaxCarryWeight; player.m_encumberedStaminaDrain = Settings.EncumberedStaminaDrain; player.m_maxPlaceDistance = Settings.MaxPlaceDistance; player.m_maxInteractDistance = Settings.MaxInteractDistance; } return instance; } public GameObject CreateInstance(Player player, string slot) { //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_04e3: Unknown result type (might be due to invalid IL or missing references) //IL_0538: Unknown result type (might be due to invalid IL or missing references) //IL_0561: Unknown result type (might be due to invalid IL or missing references) //IL_057d: Unknown result type (might be due to invalid IL or missing references) //IL_0472: Unknown result type (might be due to invalid IL or missing references) //IL_0477: Unknown result type (might be due to invalid IL or missing references) //IL_0480: Unknown result type (might be due to invalid IL or missing references) //IL_0485: Unknown result type (might be due to invalid IL or missing references) //IL_0758: Unknown result type (might be due to invalid IL or missing references) GameObject val = Object.Instantiate(VisualModel); val.SetActive(true); ((Object)val).name = slot; Transform parent = ((Component)((Component)player).GetComponentInChildren()).transform.parent; Transform val2 = parent.Find(slot); if ((Object)(object)val2 != (Object)null) { Object.Destroy((Object)(object)((Component)val2).gameObject); } val.transform.SetParent(parent, false); SkinnedMeshRenderer[] componentsInChildren = ((Character)player).GetVisual().GetComponentsInChildren(); foreach (SkinnedMeshRenderer obj in componentsInChildren) { ((Renderer)obj).forceRenderingOff = true; obj.updateWhenOffscreen = true; } LODGroup component = val.GetComponent(); LODGroup componentInChildren = ((Component)player).GetComponentInChildren(); component.fadeMode = componentInChildren.fadeMode; component.animateCrossFading = componentInChildren.animateCrossFading; Animator val3 = FieldAccess.m_animator.Invoke((Character)(object)player); val3.keepAnimatorStateOnDisable = true; val3.cullingMode = (AnimatorCullingMode)0; val.transform.localPosition = ((Component)val3).transform.localPosition; if (ModelType == Type.VRM) { float modelOffsetY = Settings.ModelOffsetY; val.RequireComponent().Setup(val3, Settings, isRagdoll: false, modelOffsetY); if (Settings.FixCameraHeight) { Animator component2 = val.GetComponent(); Transform boneTransform = component2.GetBoneTransform((HumanBodyBones)21); if ((Object)(object)boneTransform == (Object)null) { boneTransform = component2.GetBoneTransform((HumanBodyBones)10); } if ((Object)(object)boneTransform == (Object)null) { boneTransform = component2.GetBoneTransform((HumanBodyBones)9); } if ((Object)(object)boneTransform != (Object)null && slot == "VRMInstance") { ((Component)player).gameObject.RequireComponent().Setup(boneTransform); } } } else if (ModelType == Type.UnityPrefab) { val.RequireComponent().Setup(val3, Settings.HeadBone); if (Settings.FixCameraHeight) { val.GetComponent(); Transform val4 = UnityExtensions.FindDescendant(val.transform, Settings.HeadBone); if ((Object)(object)val4 != (Object)null && slot == "VRMInstance") { ((Component)player).gameObject.RequireComponent().Setup(val4); } } } if (Settings.UseMToonShader) { val.RequireComponent().Setup(val); } if (!string.IsNullOrEmpty(Settings.BlinkBlendshape)) { Debug.Log((object)("[ValheimVRM] Adding blink controller for '" + Settings.BlinkBlendshape + "'")); bool flag = false; string[] array = Settings.BlinkBlendshape.Split(new char[1] { ':' }); if (array.Length == 2 && int.TryParse(array[1], out var result)) { componentsInChildren = val.GetComponentsInChildren(); foreach (SkinnedMeshRenderer val5 in componentsInChildren) { Mesh sharedMesh = val5.sharedMesh; if (((Object)((Component)val5).gameObject).name == array[0] && result < sharedMesh.blendShapeCount) { val.RequireComponent().Setup(val5, result); Debug.Log((object)$"[ValheimVRM] found skinned mesh with blendshape {val5} {sharedMesh.GetBlendShapeName(result)}"); flag = true; break; } } } else { componentsInChildren = val.GetComponentsInChildren(); foreach (SkinnedMeshRenderer val6 in componentsInChildren) { if (val6.sharedMesh.GetBlendShapeIndex(Settings.BlinkBlendshape) >= 0) { val.RequireComponent().Setup(val6, Settings.BlinkBlendshape); Debug.Log((object)$"[ValheimVRM] found skinned mesh with blendshape {val6}"); flag = true; break; } } } if (!flag) { Debug.LogWarning((object)("[ValheimVRM] no suitable skinned mesh renderer found for blink (" + Settings.BlinkBlendshape + ")")); } } else if (slot == "VRMInstance") { val.RequireComponent().OpeningSeconds = 0.06f; } if (ModelType == Type.VRM && slot == "VRMInstance") { VRMLookAtBoneApplyer component3 = val.GetComponent(); VRMLookAtHead component4 = val.GetComponent(); VRMEyeController vRMEyeController = val.RequireComponent(); if (Object.op_Implicit((Object)(object)vRMEyeController)) { IEnumerable source = UnityExtensions.Traverse(val.transform); Transform val7 = source.FirstOrDefault((Func)((Transform x) => ((Object)x).name == left_eye_path)); Transform val8 = source.FirstOrDefault((Func)((Transform x) => ((Object)x).name == right_eye_path)); Debug.Log((object)$"[ValheimVRM] FindDescendant {val7} <-> {val8}"); vRMEyeController.LEYE = val7; vRMEyeController.REYE = val8; vRMEyeController.lookat = component3; vRMEyeController.LAh = component4; vRMEyeController.MovementMul = Settings.EyeMovementMultiplier * 0.9f; component3.LeftEye = OffsetOnTransform.Create(val7); component3.RightEye = OffsetOnTransform.Create(val8); Debug.Log((object)$"[ValheimVRM] Lookat camera test {component3}"); } else { Debug.Log((object)"[ValheimVRM] no VRMLookAtHead component found!"); } } if (slot == "VRMInstance") { CapsuleCollider component5 = ((Component)player).gameObject.GetComponent(); Debug.Log((object)$"[test]! before h:{component5.height} r:{component5.radius} c:{component5.center}"); component5.height = Settings.PlayerHeight; component5.radius = Settings.PlayerRadius; component5.center = new Vector3(0f, Settings.PlayerHeight / 2f, 0f); Debug.Log((object)$"[test]! after h:{component5.height} r:{component5.radius} c:{component5.center}"); ((Component)player).GetComponent().centerOfMass = component5.center; } if (slot == "VRMInstance" && Settings.Behavior != null) { VRMCharacterController vRMCharacterController = ((Component)player).gameObject.RequireComponent(); vRMCharacterController.machine = Settings.Behavior; vRMCharacterController.machine.Build(); Debug.Log((object)$"statemachine {vRMCharacterController.machine}"); } if (slot == "VRMInstance") { Dictionary dictionary = new Dictionary(); AnimationClip[] animationClips = val3.runtimeAnimatorController.animationClips; foreach (AnimationClip val9 in animationClips) { dictionary[((Object)val9).name] = val9; } Debug.Log((object)"animations override state"); if ((Object)(object)_the_original_player_animcontroller == (Object)null) { _the_original_player_animcontroller = val3.runtimeAnimatorController; } if (!string.IsNullOrWhiteSpace(Settings.AnimatorOverride)) { string[] array2 = Settings.AnimatorOverride.Split(new char[1] { ':' }); RuntimeAnimatorController val10 = VRMUtils.RequireBundle(array2[0]).LoadAsset(array2[1]); Debug.Log((object)$"animator {val10}"); if (Object.op_Implicit((Object)(object)val10)) { Dictionary animatorState = GetAnimatorState(val3); val3.runtimeAnimatorController = val10; SetAnimatorState(val3, animatorState); } } else if ((Object)(object)_the_original_player_animcontroller != (Object)null && (Object)(object)val3.runtimeAnimatorController != (Object)(object)_the_original_player_animcontroller) { Dictionary animatorState2 = GetAnimatorState(val3); val3.runtimeAnimatorController = _the_original_player_animcontroller; SetAnimatorState(val3, animatorState2); } } float springBoneStiffness = Settings.SpringBoneStiffness; float springBoneGravityPower = Settings.SpringBoneGravityPower; VRMSpringBone[] componentsInChildren2 = val.GetComponentsInChildren(); foreach (VRMSpringBone obj2 in componentsInChildren2) { obj2.m_stiffnessForce *= springBoneStiffness; obj2.m_gravityPower *= springBoneGravityPower; obj2.m_updateType = (SpringBoneUpdateType)1; obj2.m_center = null; } return val; } private static void SetAnimatorState(Animator orgAnim, Dictionary values) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected I4, but got Unknown AnimatorControllerParameter[] array = orgAnim.parameters.ToArray(); foreach (AnimatorControllerParameter val in array) { if (!values.TryGetValue(val.nameHash, out var value)) { continue; } AnimatorControllerParameterType type = val.type; switch (type - 1) { case 3: if (value is bool) { orgAnim.SetBool(val.nameHash, (bool)value); } break; case 2: if (value is int) { orgAnim.SetInteger(val.nameHash, (int)value); } break; case 0: if (value is float) { orgAnim.SetFloat(val.nameHash, (float)value); } break; } } } private static Dictionary GetAnimatorState(Animator orgAnim) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected I4, but got Unknown Dictionary dictionary = new Dictionary(); AnimatorControllerParameter[] array = orgAnim.parameters.ToArray(); foreach (AnimatorControllerParameter val in array) { AnimatorControllerParameterType type = val.type; switch (type - 1) { case 3: dictionary[val.nameHash] = orgAnim.GetBool(val.nameHash); break; case 2: dictionary[val.nameHash] = orgAnim.GetInteger(val.nameHash); break; case 0: dictionary[val.nameHash] = orgAnim.GetFloat(val.nameHash); break; } } return dictionary; } } public class VRMSettings : SettingsBase { public string ModelType = "vrm"; public string PrefabName = "Default"; public string HeadBone = "Head"; public bool FixCameraHeight = true; public bool UseMToonShader; public bool EnablePlayerFade = true; public float ModelScale = 1.1f; public float ModelOffsetY; public float SpringBoneStiffness = 1f; public float SpringBoneGravityPower = 1f; public float ModelBrightness = 0.8f; public float PlayerHeight = 1.85f; public float PlayerRadius = 0.5f; public string BlinkBlendshape; public Vector3 LeftHandEuqipPos; public Vector3 RightHandEuqipPos; public Vector3 LeftHandBackItemPos; public Vector3 RightHandBackItemPos; public Vector3 SittingIdleOffset; public Vector3 SittingOnChairOffset; public Vector3 SittingOnThroneOffset; public Vector3 SittingOnShipOffset; public Vector3 HoldingMastOffset; public Vector3 HoldingDragonOffset; public Vector3 SleepingOffset; public bool HideHair = true; public bool HideBeard = true; public bool HideHelmet = true; public bool HideShoulder = true; public bool HideChest = true; public bool HideLegs = true; public bool HideUtility = true; public string ItemOverrides; public string ItemOverridesBack; public string AnimatorOverride; public bool LegAffectsSpeed; public float EyeMovementMultiplier = 1f; public float CrouchingHeight = 1.85f; public VRMCharacterController.StateMachine Behavior; public float BaseHP = 25f; public float BaseStamina = 50f; public float SwimDepth = 1.5f; public float SwimSpeed = 2f; public bool CanSwim = true; public float JumpStaminaUsage = 10f; public bool CanFly; public float FlySlowSpeed = 5f; public float FlyFastSpeed = 12f; public float FlyTurnSpeed = 12f; public float FlightStaminaUsage = 10f; public float FastFlightStaminaUsage = 20f; public bool NoFallDamage; public float RunStaminaDrain = 8f; public float SneakStaminaDrain = 5f; public float SwimStaminaDrainMinSkill = 6f; public float SwimStaminaDrainMaxSkill = 3f; public float DodgeStaminaUsage = 15f; public float WeightStaminaFactor = 0.1f; public float MaxCarryWeight = 300f; public float EncumberedStaminaDrain = 5f; public float MaxPlaceDistance = 8f; public float MaxInteractDistance = 3.5f; public string DisplayName; public string Ability1; [NonSerialized] public Dictionary _ItemOverrides = new Dictionary(); [NonSerialized] public Dictionary _ItemOverridesBack = new Dictionary(); private static Dictionary public_fields = SettingsBase.PopulateFieldInfo(); public override Dictionary Load(Dictionary settings) { Dictionary dictionary = new Dictionary(); LoadValues(settings, dictionary, public_fields); _ItemOverrides.Clear(); _ItemOverridesBack.Clear(); if (!string.IsNullOrWhiteSpace(ItemOverrides)) { string[] array = ItemOverrides.Split(new char[1] { ';' }); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[1] { '-' }); _ItemOverrides.Add(StringExtensionMethods.GetStableHashCode(array2[0].Trim()), array2[1].Trim()); } } if (!string.IsNullOrWhiteSpace(ItemOverridesBack)) { string[] array = ItemOverridesBack.Split(new char[1] { ';' }); for (int i = 0; i < array.Length; i++) { string[] array3 = array[i].Split(new char[1] { '-' }); _ItemOverridesBack.Add(StringExtensionMethods.GetStableHashCode(array3[0].Trim()), array3[1].Trim()); } } return dictionary; } public Dictionary GetChanges(VRMSettings oldSettings) { Dictionary dictionary = new Dictionary(); if (oldSettings != null) { foreach (KeyValuePair public_field in public_fields) { object value = public_field.Value.info.GetValue(oldSettings); object value2 = public_field.Value.info.GetValue(this); if (value != value2) { dictionary.Add(public_field.Key, value); } } } return dictionary; } public void ApplyChanges(VRMModel model, Dictionary old_values) { //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: 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) Lazy> lazy = new Lazy>(() => VRMManager.GetInstancesOf(model)); foreach (KeyValuePair old_value in old_values) { switch (old_value.Key) { case "ModelScale": model.VisualModel.transform.localScale = Vector3.one * ModelScale; foreach (VRMModel.Instance item in lazy.Value) { if (Object.op_Implicit((Object)(object)item.gameObject)) { item.gameObject.transform.localScale = Vector3.one * ModelScale; } } break; case "SpringBoneStiffness": foreach (VRMModel.Instance item2 in lazy.Value) { if (Object.op_Implicit((Object)(object)item2.gameObject)) { VRMSpringBone[] componentsInChildren = item2.gameObject.GetComponentsInChildren(); foreach (VRMSpringBone obj2 in componentsInChildren) { obj2.m_stiffnessForce = obj2.m_stiffnessForce / (float)old_value.Value * SpringBoneStiffness; } } } break; case "SpringBoneGravityPower": foreach (VRMModel.Instance item3 in lazy.Value) { if (Object.op_Implicit((Object)(object)item3.gameObject)) { VRMSpringBone[] componentsInChildren = item3.gameObject.GetComponentsInChildren(); foreach (VRMSpringBone obj in componentsInChildren) { obj.m_gravityPower = obj.m_gravityPower / (float)old_value.Value * SpringBoneGravityPower; } } } break; case "ModelOffsetY": foreach (VRMModel.Instance item4 in lazy.Value) { if (Object.op_Implicit((Object)(object)item4.gameObject)) { item4.gameObject.GetComponent().offset = ModelOffsetY; } } break; case "Behavior": foreach (VRMModel.Instance item5 in lazy.Value) { if (Object.op_Implicit((Object)(object)item5.player)) { VRMCharacterController vRMCharacterController = ((Component)item5.player).gameObject.RequireComponent(); vRMCharacterController.machine = Behavior; vRMCharacterController.machine.Build(); } } break; } } } } public static class VRMShaders { public static Dictionary Shaders { get; } = new Dictionary(); public static void Initialize() { string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ValheimVRM.shaders"); if (File.Exists(text)) { Shader[] array = AssetBundle.LoadFromFile(text).LoadAllAssets(); foreach (Shader val in array) { Debug.Log((object)("[ValheimVRM] Add Shader: " + ((Object)val).name)); Shaders.Add(((Object)val).name, val); } } } } } namespace ValheimVRM.vrmtf { public static class VRMTF { public static Material TFMaterial; static VRMTF() { string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "vrmtf"); if (File.Exists(text)) { TFMaterial = AssetBundle.LoadFromFile(text).LoadAsset("SampleTF"); } } public static void DoTransform(Player player, string target_vrm, float tf_time = 1f) { DoTransformLocal(player, target_vrm, tf_time); Debug.Log((object)$"[VRMTF] DoTransform {player} {target_vrm} {tf_time}"); player.m_customData.Set("vrm_form", target_vrm); FieldAccess.m_nview.Invoke(player).GetZDO().Set(VRMTFController.vrm_form, target_vrm ?? ""); if (target_vrm == null) { return; } try { ZRoutedRpc instance = ZRoutedRpc.instance; if (instance != null) { instance.InvokeRoutedRPC(ZNetView.Everybody, "RPC_Transform", new object[3] { player.GetPlayerID(), target_vrm, tf_time }); } } catch (Exception ex) { Debug.LogException(ex); } } public static void DoTransformLocal(Player player, string target_vrm, float tf_time = 1f) { Debug.Log((object)$"[VRMTF] DoTransformLocal {player} {target_vrm} {tf_time}"); if (tf_time <= 0f) { VRMManager.GetVRMInstance(player)?.Remove(); VRMManager.LoadAndSetupByPlayerName(player, target_vrm); } else if (VRMManager.GetVRMInstance(player) != null) { VRMTFController.Transform(player, target_vrm); } } public static void RPC_Transform(long sender, long pid, string form, float tf_time) { Player player = Player.GetPlayer(pid); if (!((Object)(object)player == (Object)null)) { DoTransformLocal(player, form, tf_time); } } } [HarmonyPatch(typeof(Game), "Start")] public static class GameStartPatch { private static void Prefix() { ZRoutedRpc.instance.Register("RPC_Transform", (Action)VRMTF.RPC_Transform); Debug.Log((object)"[VRMTF] registered rpcs"); } } public class VRMTFController : MonoBehaviour { public static int vrm_form = StringExtensionMethods.GetStableHashCode("vrm_form"); public Player player; public string target_vrm; public float duration = 5f; private float progress; private bool in_progress; private VRMModel.Instance current_vrm; private VRMModel.Instance next_vrm; private VRMModel.Instance tf0; private VRMModel.Instance tf1; private List materials; public static void Transform(Player player, string target_vrm) { if (!((Object)(object)player == (Object)null)) { if (Object.op_Implicit((Object)(object)((Component)player).GetComponent())) { Debug.LogWarning((object)$"{player} already has VRMTFController"); return; } VRMTFController vRMTFController = ((Component)player).gameObject.AddComponent(); vRMTFController.player = player; vRMTFController.target_vrm = target_vrm; } } private IEnumerator _DoTransform() { yield return (object)new WaitForSeconds(10f); } private void Start() { try { current_vrm = VRMManager.GetVRMInstance(player); tf0 = VRMManager.LoadAndSetupByPlayerName(player, current_vrm.model.Name, "tf0"); tf1 = VRMManager.LoadAndSetupByPlayerName(player, target_vrm, "tf1"); materials = ModifyMaterials(tf0.gameObject, -1f); materials.AddRange(ModifyMaterials(tf1.gameObject)); progress = 0f; in_progress = true; current_vrm.Remove(); next_vrm = VRMManager.LoadAndSetupByPlayerName(player, target_vrm); next_vrm.SetVisible(enabled: false); player.m_customData.Set("vrm_form", target_vrm); FieldAccess.m_nview.Invoke(player).GetZDO().Set(vrm_form, target_vrm ?? ""); } catch (Exception ex) { Debug.LogException(ex); Object.Destroy((Object)(object)this); } } private void Update() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) if (!in_progress) { return; } Vector3 position = ((Component)this).transform.position; progress += Time.deltaTime / duration; foreach (Material material in materials) { material.SetFloat("_Progress", (1f - progress) * 1.3f); material.SetVector("_Offset", Vector4.op_Implicit(position)); } if (progress >= 1f) { progress = 1f; next_vrm.SetVisible(enabled: true); tf0.Remove(); tf1.Remove(); Object.Destroy((Object)(object)this); } } public List ModifyMaterials(GameObject gameObject, float direction = 1f) { //IL_00d5: Unknown result type (might be due to invalid IL or missing references) List list = new List(); SkinnedMeshRenderer[] componentsInChildren = gameObject.GetComponentsInChildren(); for (int i = 0; i < componentsInChildren.Length; i++) { Material[] array = ((Renderer)componentsInChildren[i]).materials; foreach (Material item in array) { if (!list.Contains(item)) { list.Add(item); } } } MeshRenderer[] componentsInChildren2 = gameObject.GetComponentsInChildren(); for (int i = 0; i < componentsInChildren2.Length; i++) { Material[] array = ((Renderer)componentsInChildren2[i]).materials; foreach (Material item2 in array) { if (!list.Contains(item2)) { list.Add(item2); } } } Material tFMaterial = VRMTF.TFMaterial; foreach (Material item3 in list) { item3.shader = tFMaterial.shader; item3.SetColor("_LineColor", tFMaterial.GetColor("_LineColor")); item3.SetFloat("_Direction", direction); item3.SetTexture("_MainTex", item3.GetTexture("_LegsTex")); item3.SetTexture("_BumpMap", item3.GetTexture("_LegsBumpMap")); item3.SetFloat("_Glossiness", item3.GetFloat("_Glossiness")); } return list; } } }