using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; using BoneHub; using BoneHub.Compatibility; using BoneHub.Interaction; using BoneHub.Mod; using BoneHub.Models; using BoneLib; using HarmonyLib; using Il2CppSLZ.Bonelab; using Il2CppSLZ.Marrow; using LabFusion.Network; using MelonLoader; using MelonLoader.Preferences; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("WristHub.Build49.Extension")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("4.4.5.0")] [assembly: AssemblyInformationalVersion("4.4.5")] [assembly: AssemblyProduct("WristHub.Build49.Extension")] [assembly: AssemblyTitle("WristHub.Build49.Extension")] [assembly: AssemblyVersion("4.4.5.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace BoneHub.Compatibility { public static class Dev49FusionPortalRepairPolicy { public static bool ShouldUseObservedJoin(bool hasServer) { return !hasServer; } } } namespace BoneHub.Mod { internal sealed class SpawnPreviewSourceState { private readonly List<(Rigidbody Body, bool IsKinematic, bool UseGravity, bool DetectCollisions, RigidbodyConstraints Constraints, Vector3 Velocity, Vector3 AngularVelocity, CollisionDetectionMode CollisionMode, RigidbodyInterpolation Interpolation)> _bodies = new List<(Rigidbody, bool, bool, bool, RigidbodyConstraints, Vector3, Vector3, CollisionDetectionMode, RigidbodyInterpolation)>(); private readonly List<(Collider Collider, bool Enabled)> _colliders = new List<(Collider, bool)>(); private readonly List<(AudioSource Audio, bool Enabled, bool Mute, float Volume)> _audio = new List<(AudioSource, bool, bool, float)>(); private readonly List<(Behaviour Behaviour, bool Enabled)> _behaviours = new List<(Behaviour, bool)>(); private bool _restored; internal static SpawnPreviewSourceState SuspendInPlace(GameObject source, bool disableBehaviours) { SpawnPreviewSourceState spawnPreviewSourceState = new SpawnPreviewSourceState(); if ((Object)(object)source == (Object)null) { return spawnPreviewSourceState; } spawnPreviewSourceState.Capture(source, disableBehaviours); return spawnPreviewSourceState; } private void Capture(GameObject source, bool disableBehaviours) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) foreach (Rigidbody componentsInChild in source.GetComponentsInChildren(true)) { if (!((Object)(object)componentsInChild == (Object)null)) { _bodies.Add((componentsInChild, componentsInChild.isKinematic, componentsInChild.useGravity, componentsInChild.detectCollisions, componentsInChild.constraints, componentsInChild.velocity, componentsInChild.angularVelocity, componentsInChild.collisionDetectionMode, componentsInChild.interpolation)); componentsInChild.velocity = Vector3.zero; componentsInChild.angularVelocity = Vector3.zero; componentsInChild.detectCollisions = false; componentsInChild.useGravity = false; componentsInChild.isKinematic = true; } } foreach (Collider componentsInChild2 in source.GetComponentsInChildren(true)) { if (!((Object)(object)componentsInChild2 == (Object)null)) { _colliders.Add((componentsInChild2, componentsInChild2.enabled)); componentsInChild2.enabled = false; } } foreach (AudioSource componentsInChild3 in source.GetComponentsInChildren(true)) { if (!((Object)(object)componentsInChild3 == (Object)null)) { _audio.Add((componentsInChild3, ((Behaviour)componentsInChild3).enabled, componentsInChild3.mute, componentsInChild3.volume)); try { componentsInChild3.Stop(); } catch { } componentsInChild3.mute = true; ((Behaviour)componentsInChild3).enabled = false; } } if (!disableBehaviours) { return; } foreach (Behaviour componentsInChild4 in source.GetComponentsInChildren(true)) { if (!((Object)(object)componentsInChild4 == (Object)null) && !(componentsInChild4 is AudioSource)) { _behaviours.Add((componentsInChild4, componentsInChild4.enabled)); try { componentsInChild4.enabled = false; } catch { } } } } internal void Restore() { //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) if (_restored) { return; } _restored = true; foreach (var behaviour in _behaviours) { try { if ((Object)(object)behaviour.Behaviour != (Object)null) { behaviour.Behaviour.enabled = behaviour.Enabled; } } catch { } } foreach (var collider in _colliders) { try { if ((Object)(object)collider.Collider != (Object)null) { collider.Collider.enabled = collider.Enabled; } } catch { } } foreach (var item in _audio) { try { if (!((Object)(object)item.Audio == (Object)null)) { item.Audio.volume = item.Volume; item.Audio.mute = item.Mute; ((Behaviour)item.Audio).enabled = item.Enabled; } } catch { } } foreach (var body in _bodies) { try { if (!((Object)(object)body.Body == (Object)null)) { body.Body.constraints = body.Constraints; body.Body.isKinematic = body.IsKinematic; body.Body.useGravity = body.UseGravity; body.Body.detectCollisions = body.DetectCollisions; body.Body.collisionDetectionMode = body.Rest.Item1; body.Body.interpolation = body.Rest.Item2; body.Body.velocity = body.Velocity; body.Body.angularVelocity = body.AngularVelocity; if (!body.Body.isKinematic) { body.Body.WakeUp(); } } } catch { } } _behaviours.Clear(); _colliders.Clear(); _audio.Clear(); _bodies.Clear(); } } } namespace WristHub.Build49Extension { internal static class Dev49CallCameraControls { private enum CameraAction { VolumeDown, ToggleMute, VolumeUp, CycleCameraMode, ToggleSpeaker, InviteCallParticipant } private readonly record struct ButtonVisual(GameObject? Root, Renderer? Renderer, TextMesh? Label, CameraAction Action); private const float MinimumVolume = 0f; private const float MaximumVolume = 1f; private const float VolumeStep = 0.1f; private const float TouchReleaseSeconds = 0.18f; private const string ControlsName = "[WristHub] Call Camera Controls"; private static readonly FieldInfo CameraVisualRootField = typeof(WristHubVideoCallRuntime).GetField("_cameraVisualRoot", BindingFlags.Static | BindingFlags.NonPublic); private static readonly FieldInfo PlaybackField = typeof(WristHubWebRtcVoiceRuntime).GetField("_playback", BindingFlags.Static | BindingFlags.NonPublic); private static readonly FieldInfo PlaybackSourceField = typeof(WristHubWebRtcAudioPlayback).GetField("_source", BindingFlags.Instance | BindingFlags.NonPublic); private static readonly ButtonVisual[] Buttons = new ButtonVisual[6]; private static readonly bool[,] WasInside = new bool[6, 2]; private static Instance? _log; private static MelonPreferences_Category? _preferences; private static MelonPreferences_Entry? _volumePreference; private static MelonPreferences_Entry? _speakerPreference; private static Transform? _boundVisualRoot; private static GameObject? _controlsRoot; private static Material? _idleMaterial; private static Material? _activeMaterial; private static Material? _mutedMaterial; private static TextMesh? _volumeStatus; private static TextMesh? _inviteStatus; private static GameObject? _intakeOutline; private static float _remoteVolume = 1f; private static float _nextTouchAt; private static float _nextAudioApplyAt; private static AudioSource? _lastSource; private static int _lastVolumePercent = int.MinValue; private static int _lastMuteState = -1; private static int _lastCameraMode = -1; private static int _lastSpeakerState = -1; private static int _inviteResultState; private static float _inviteStatusUntil; private static string _boundCallId = string.Empty; internal static void Initialize(Instance log) { _log = log; _preferences = MelonPreferences.CreateCategory("WristHubCalls"); _volumePreference = _preferences.CreateEntry("RemoteVolume", 1f, "Remote call volume", (string)null, false, false, (ValueValidator)null, (string)null); _speakerPreference = _preferences.CreateEntry("SpeakerMode", false, "Play the remote caller to the current Fusion lobby", (string)null, false, false, (ValueValidator)null, (string)null); _remoteVolume = Mathf.Clamp(_volumePreference.Value, 0f, 1f); if (!Mathf.Approximately(_volumePreference.Value, _remoteVolume)) { _volumePreference.Value = _remoteVolume; SavePreferences(); } WristHubWebRtcAudioPlayback.SetSpeakerMode(_speakerPreference.Value); } internal static void Tick() { //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) WristHubWebRtcCallSnapshot current = WristHubWebRtcVoiceRuntime.Current; string text = default(string); string text2 = default(string); string text3 = default(string); string text4 = default(string); bool flag = WristHubSocialRelay.TryGetActiveCallPresentation(ref text, ref text2, ref text3, ref text4); object? value = CameraVisualRootField.GetValue(null); Transform val = (Transform)((value is Transform) ? value : null); if ((Object)(object)val == (Object)null || (!current.IsActive && !flag)) { ReleaseVisuals(); ApplyRemoteVolume(force: false); return; } if ((Object)(object)_boundVisualRoot != (Object)(object)val || (Object)(object)_controlsRoot == (Object)null) { BuildControls(val); } if ((Object)(object)_controlsRoot == (Object)null) { return; } if (flag && text4.Length > 0 && !_boundCallId.Equals(text4, StringComparison.Ordinal)) { _boundCallId = text4; ClearInviteStatus(); ClearTouchState(); } if (_controlsRoot.activeSelf != ((Component)val).gameObject.activeInHierarchy) { _controlsRoot.SetActive(((Component)val).gameObject.activeInHierarchy); } RefreshVisualState(); ApplyRemoteVolume(force: false); if (!_controlsRoot.activeInHierarchy) { return; } IReadOnlyList probes = BoneHubFingertipProbeProvider.Shared.GetProbes(); for (int i = 0; i < Buttons.Length; i++) { ButtonVisual buttonVisual = Buttons[i]; if ((Object)(object)buttonVisual.Root == (Object)null) { continue; } bool flag2 = false; bool flag3 = false; for (int j = 0; j < probes.Count; j++) { BoneHubFingertipProbe val2 = probes[j]; int num = ((!((BoneHubFingertipProbe)(ref val2)).IsLeft) ? 1 : 0); if (((BoneHubFingertipProbe)(ref val2)).IsLeft) { flag2 = true; } else { flag3 = true; } Vector3 val3 = buttonVisual.Root.transform.InverseTransformPoint(((BoneHubFingertipProbe)(ref val2)).Position); bool flag4 = Mathf.Abs(val3.x) <= 0.68f && Mathf.Abs(val3.y) <= 0.72f && Mathf.Abs(val3.z) <= 1.45f; bool flag5 = WristHubVideoCallRuntime.IsCallCameraControlInputBlocked(((BoneHubFingertipProbe)(ref val2)).IsLeft); if (flag4 && !flag5 && !WasInside[i, num] && Time.unscaledTime >= _nextTouchAt) { _nextTouchAt = Time.unscaledTime + 0.18f; Activate(buttonVisual.Action); } WasInside[i, num] = flag4; } if (!flag2) { WasInside[i, 0] = false; } if (!flag3) { WasInside[i, 1] = false; } } } internal static void OnSceneChanged() { _lastSource = null; _nextAudioApplyAt = 0f; ClearTouchState(); } internal static void Shutdown() { ReleaseVisuals(); DestroyMaterial(ref _idleMaterial); DestroyMaterial(ref _activeMaterial); DestroyMaterial(ref _mutedMaterial); _preferences = null; _volumePreference = null; _speakerPreference = null; _lastSource = null; _log = null; } private static void BuildControls(Transform visualRoot) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) ReleaseVisuals(); _boundVisualRoot = visualRoot; GameObject val = new GameObject("[WristHub] Call Camera Controls"); val.transform.SetParent(visualRoot, false); val.transform.localPosition = Vector3.zero; val.transform.localRotation = Quaternion.identity; val.transform.localScale = Vector3.one; val.layer = ((Component)visualRoot).gameObject.layer; _controlsRoot = val; EnsureMaterials(); _intakeOutline = BuildTransferIntakeOutline(val.transform, val.layer); _volumeStatus = BuildStatusLabel(val.transform, val.layer); Buttons[0] = BuildButton(val.transform, "Volume Down", "VOL -", new Vector3(-0.06f, -0.069f, 0.029f), CameraAction.VolumeDown); Buttons[1] = BuildButton(val.transform, "Microphone Mute", "MIC", new Vector3(-0.02f, -0.069f, 0.029f), CameraAction.ToggleMute); Buttons[2] = BuildButton(val.transform, "Volume Up", "VOL +", new Vector3(0.02f, -0.069f, 0.029f), CameraAction.VolumeUp); Buttons[3] = BuildButton(val.transform, "Camera Angle", "VIEW", new Vector3(-0.03f, 0.055f, 0.029f), CameraAction.CycleCameraMode); Buttons[4] = BuildButton(val.transform, "Lobby Speaker", "SPKR", new Vector3(0.03f, 0.055f, 0.029f), CameraAction.ToggleSpeaker); Buttons[5] = BuildButton(val.transform, "Invite Call Participant", "INVITE", new Vector3(0f, 0.08f, 0.029f), CameraAction.InviteCallParticipant); _inviteStatus = BuildInviteStatusLabel(val.transform, val.layer); ClearTouchState(); RefreshVisualState(); } private static ButtonVisual BuildButton(Transform parent, string name, string label, Vector3 position, CameraAction action) { //IL_0021: 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_004c: 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_00bc: 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_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_0102: 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_0121: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.CreatePrimitive((PrimitiveType)0); ((Object)val).name = name; val.transform.SetParent(parent, false); val.transform.localPosition = position; val.transform.localRotation = Quaternion.identity; val.transform.localScale = new Vector3(0.034f, 0.017f, 0.008f); val.layer = ((Component)parent).gameObject.layer; Collider component = val.GetComponent(); if ((Object)(object)component != (Object)null) { component.enabled = false; Object.Destroy((Object)(object)component); } Renderer component2 = val.GetComponent(); if ((Object)(object)component2 != (Object)null && (Object)(object)_idleMaterial != (Object)null) { component2.sharedMaterial = _idleMaterial; } GameObject val2 = new GameObject(name + " Label"); val2.transform.SetParent(val.transform, false); val2.transform.localPosition = new Vector3(0f, 0f, 0.56f); val2.transform.localRotation = Quaternion.Euler(0f, 180f, 0f); val2.transform.localScale = new Vector3(20f, 38f, 18f); val2.layer = ((Component)parent).gameObject.layer; TextMesh val3 = val2.AddComponent(); val3.text = label; val3.anchor = (TextAnchor)4; val3.alignment = (TextAlignment)1; val3.fontSize = 30; val3.characterSize = 0.0052f; val3.color = Color.white; val3.richText = false; return new ButtonVisual(val, component2, val3, action); } private static GameObject BuildTransferIntakeOutline(Transform parent, int layer) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_007c: 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_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: 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_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Expected O, but got Unknown GameObject val = new GameObject("Camera Item Transfer Intake"); val.transform.SetParent(parent, false); val.transform.localPosition = Vector3.zero; val.transform.localRotation = Quaternion.identity; val.transform.localScale = Vector3.one; val.layer = layer; AddOutlineBar(val.transform, "Transfer Intake Top", new Vector3(0f, 0.0405f, 0.02f), new Vector3(0.134f, 0.003f, 0.003f), layer); AddOutlineBar(val.transform, "Transfer Intake Bottom", new Vector3(0f, -0.0405f, 0.02f), new Vector3(0.134f, 0.003f, 0.003f), layer); AddOutlineBar(val.transform, "Transfer Intake Left", new Vector3(-0.067f, 0f, 0.02f), new Vector3(0.003f, 0.081f, 0.003f), layer); AddOutlineBar(val.transform, "Transfer Intake Right", new Vector3(0.067f, 0f, 0.02f), new Vector3(0.003f, 0.081f, 0.003f), layer); return val; } private static void AddOutlineBar(Transform parent, string name, Vector3 position, Vector3 scale, int layer) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3); ((Object)obj).name = name; obj.transform.SetParent(parent, false); obj.transform.localPosition = position; obj.transform.localRotation = Quaternion.identity; obj.transform.localScale = scale; obj.layer = layer; Collider component = obj.GetComponent(); if ((Object)(object)component != (Object)null) { component.enabled = false; Object.Destroy((Object)(object)component); } Renderer component2 = obj.GetComponent(); if ((Object)(object)component2 != (Object)null && (Object)(object)_activeMaterial != (Object)null) { component2.sharedMaterial = _activeMaterial; } } private static TextMesh BuildStatusLabel(Transform parent, int layer) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("Remote Volume Status"); val.transform.SetParent(parent, false); val.transform.localPosition = new Vector3(0f, -0.05f, 0.029f); val.transform.localRotation = Quaternion.Euler(0f, 180f, 0f); val.transform.localScale = Vector3.one; val.layer = layer; TextMesh obj = val.AddComponent(); obj.anchor = (TextAnchor)4; obj.alignment = (TextAlignment)1; obj.fontSize = 28; obj.characterSize = 0.0038f; obj.color = Color.white; obj.richText = false; return obj; } private static TextMesh BuildInviteStatusLabel(Transform parent, int layer) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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_0065: 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) GameObject val = new GameObject("Lobby Invite Status"); val.transform.SetParent(parent, false); val.transform.localPosition = new Vector3(0f, 0.101f, 0.029f); val.transform.localRotation = Quaternion.Euler(0f, 180f, 0f); val.transform.localScale = Vector3.one; val.layer = layer; TextMesh obj = val.AddComponent(); obj.text = string.Empty; obj.anchor = (TextAnchor)4; obj.alignment = (TextAlignment)1; obj.fontSize = 26; obj.characterSize = 0.0032f; obj.color = Color.white; obj.richText = false; return obj; } private static void Activate(CameraAction action) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Invalid comparison between Unknown and I4 //IL_007b: 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_007a: Unknown result type (might be due to invalid IL or missing references) switch (action) { case CameraAction.VolumeDown: SetRemoteVolume(_remoteVolume - 0.1f); break; case CameraAction.VolumeUp: SetRemoteVolume(_remoteVolume + 0.1f); break; case CameraAction.ToggleMute: WristHubWebRtcVoiceRuntime.SetMuted(!WristHubWebRtcVoiceRuntime.IsMuted); break; case CameraAction.CycleCameraMode: { WristHubCallCameraMode localCameraMode = WristHubSocialRelay.ActiveCallMedia.LocalCameraMode; WristHubCallCameraMode val = (((int)localCameraMode == 0) ? ((WristHubCallCameraMode)1) : (((int)localCameraMode != 1) ? ((WristHubCallCameraMode)0) : ((WristHubCallCameraMode)2))); string text = default(string); if (!WristHubSocialRelay.SetCallCameraMode(val, ref text)) { Instance? log = _log; if (log != null) { log.Warning("WristHub call-camera VIEW button could not change angle: " + text); } } break; } case CameraAction.ToggleSpeaker: { bool flag = !WristHubWebRtcAudioPlayback.SpeakerModeEnabled; WristHubWebRtcAudioPlayback.SetSpeakerMode(flag); if (_speakerPreference != null) { _speakerPreference.Value = flag; } SavePreferences(); break; } case CameraAction.InviteCallParticipant: InviteActiveCallParticipant(); break; } RefreshVisualState(); } private static void InviteActiveCallParticipant() { string text = default(string); string text2 = default(string); string text3 = default(string); string text4 = default(string); if (!WristHubSocialRelay.TryGetActiveCallPresentation(ref text, ref text2, ref text3, ref text4) || text4.Length == 0 || (!_boundCallId.Equals(text4, StringComparison.Ordinal) && _boundCallId.Length > 0)) { ShowInviteStatus("CALL ENDED\nNOT INVITED", succeeded: false); return; } ulong activeCallPlatformId = WristHubSocialRelay.ActiveCallPlatformId; if (activeCallPlatformId == 0L) { ShowInviteStatus("CALL FRIEND\nNOT READY", succeeded: false); return; } string text5 = default(string); bool flag = WristHubSocialRelay.TryInviteToCurrentLobby(activeCallPlatformId, ref text5); ShowInviteStatus(CameraInviteStatus(text5, flag), flag); if (!flag) { Instance? log = _log; if (log != null) { log.Warning("WristHub call-camera INVITE could not send: " + text5); } } } private static string CameraInviteStatus(string status, bool succeeded) { string text = status?.Trim().ToUpperInvariant() ?? string.Empty; if (succeeded) { if (text.Contains("STARTING FUSION LOBBY", StringComparison.Ordinal)) { return "STARTING LOBBY\nINVITE WILL SEND"; } if (text.Contains("USING CURRENT FUSION LOBBY", StringComparison.Ordinal) || text.Contains("WAITING FOR YOUR FUSION LOBBY", StringComparison.Ordinal)) { return "WAITING FOR LOBBY\nINVITE WILL SEND"; } if (text.Contains("INVITE SENT", StringComparison.Ordinal)) { return "INVITE SENT"; } return "INVITE QUEUED"; } if (text.Contains("MEET OR LINK", StringComparison.Ordinal)) { return "FRIEND NOT LINKED"; } if (text.Contains("LOBBY", StringComparison.Ordinal) && (text.Contains("FAILED", StringComparison.Ordinal) || text.Contains("COULD NOT", StringComparison.Ordinal))) { return "LOBBY FAILED\nINVITE NOT SENT"; } if (text.Contains("TOO MANY", StringComparison.Ordinal)) { return "INVITE QUEUE FULL"; } return "INVITE FAILED\nTRY AGAIN"; } private static void ShowInviteStatus(string status, bool succeeded) { //IL_004f: 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) if ((Object)(object)_inviteStatus != (Object)null) { _inviteStatus.text = status; _inviteStatus.color = (succeeded ? new Color(0.18f, 1f, 0.58f, 1f) : new Color(1f, 0.34f, 0.3f, 1f)); } _inviteResultState = (succeeded ? 1 : (-1)); _inviteStatusUntil = Time.unscaledTime + (succeeded ? 5f : 7f); } private static void ClearInviteStatus() { if ((Object)(object)_inviteStatus != (Object)null) { _inviteStatus.text = string.Empty; } _inviteResultState = 0; _inviteStatusUntil = 0f; } private static void SetRemoteVolume(float value) { value = Mathf.Round(Mathf.Clamp(value, 0f, 1f) * 10f) / 10f; if (!Mathf.Approximately(value, _remoteVolume)) { _remoteVolume = value; if (_volumePreference != null) { _volumePreference.Value = value; } SavePreferences(); ApplyRemoteVolume(force: true); } } private static void ApplyRemoteVolume(bool force) { if (!force && Time.unscaledTime < _nextAudioApplyAt) { return; } _nextAudioApplyAt = Time.unscaledTime + 0.25f; try { object value = PlaybackField.GetValue(null); AudioSource val = (AudioSource)((value == null) ? null : /*isinst with value type is only supported in some contexts*/); if ((Object)(object)val == (Object)null) { _lastSource = null; return; } if (force || (Object)(object)_lastSource != (Object)(object)val || !Mathf.Approximately(val.volume, _remoteVolume)) { val.volume = _remoteVolume; } _lastSource = val; } catch (Exception ex) { Instance? log = _log; if (log != null) { log.Warning("WristHub call volume will retry safely: " + ex.GetBaseException().Message); } } } private static void RefreshVisualState() { //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Expected I4, but got Unknown //IL_0134: 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_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Invalid comparison between Unknown and I4 int num = ((_remoteVolume <= 0.001f) ? (-1) : Mathf.RoundToInt(_remoteVolume * 100f)); if ((Object)(object)_volumeStatus != (Object)null && num != _lastVolumePercent) { _volumeStatus.text = ((num < 0) ? "VOL OFF" : $"VOL {num}%"); _lastVolumePercent = num; } int num2 = (WristHubWebRtcVoiceRuntime.IsMuted ? 1 : 0); TextMesh label = Buttons[1].Label; if ((Object)(object)label != (Object)null && num2 != _lastMuteState) { label.text = ((num2 != 0) ? "MIC OFF" : "MIC"); } Renderer renderer = Buttons[1].Renderer; if ((Object)(object)renderer != (Object)null && num2 != _lastMuteState) { renderer.sharedMaterial = ((num2 != 0) ? _mutedMaterial : _activeMaterial); } _lastMuteState = num2; int num3 = (int)WristHubSocialRelay.ActiveCallMedia.LocalCameraMode; TextMesh label2 = Buttons[3].Label; if ((Object)(object)label2 != (Object)null && num3 != _lastCameraMode) { TextMesh val = label2; WristHubCallCameraMode val2 = (WristHubCallCameraMode)num3; string text = (((int)val2 == 0) ? "FACE" : (((int)val2 != 1) ? "FREE" : "POV")); val.text = text; } _lastCameraMode = num3; int num4 = (WristHubWebRtcAudioPlayback.SpeakerModeEnabled ? 1 : 0); TextMesh label3 = Buttons[4].Label; if ((Object)(object)label3 != (Object)null && num4 != _lastSpeakerState) { label3.text = ((num4 != 0) ? "SPK ON" : "SPKR"); } Renderer renderer2 = Buttons[4].Renderer; if ((Object)(object)renderer2 != (Object)null && num4 != _lastSpeakerState) { renderer2.sharedMaterial = ((num4 != 0) ? _activeMaterial : _idleMaterial); } _lastSpeakerState = num4; if (_inviteStatusUntil > 0f && Time.unscaledTime >= _inviteStatusUntil) { ClearInviteStatus(); } Renderer renderer3 = Buttons[5].Renderer; if ((Object)(object)renderer3 != (Object)null) { int inviteResultState = _inviteResultState; Material sharedMaterial = ((inviteResultState > 0) ? _activeMaterial : ((inviteResultState >= 0) ? _idleMaterial : _mutedMaterial)); renderer3.sharedMaterial = sharedMaterial; } if ((Object)(object)_intakeOutline != (Object)null) { bool intakeActive = WristHubCallItemTransferRuntime.IntakeActive; if (_intakeOutline.activeSelf != intakeActive) { _intakeOutline.SetActive(intakeActive); } } } private static void EnsureMaterials() { //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_idleMaterial != (Object)null) || !((Object)(object)_activeMaterial != (Object)null) || !((Object)(object)_mutedMaterial != (Object)null)) { Shader val = Shader.Find("Universal Render Pipeline/Unlit") ?? Shader.Find("SLZ/Unlit") ?? Shader.Find("Unlit/Color") ?? Shader.Find("Sprites/Default"); if (!((Object)(object)val == (Object)null)) { _idleMaterial = NewMaterial(val, "Call Control", new Color(0.09f, 0.18f, 0.24f, 1f)); _activeMaterial = NewMaterial(val, "Call Control Active", new Color(0.03f, 0.58f, 0.37f, 1f)); _mutedMaterial = NewMaterial(val, "Call Control Muted", new Color(0.82f, 0.12f, 0.22f, 1f)); } } } private static Material NewMaterial(Shader shader, string name, Color color) { //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_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_001f: Expected O, but got Unknown return new Material(shader) { name = "WristHub " + name, color = color }; } private static void SavePreferences() { try { MelonPreferences_Category? preferences = _preferences; if (preferences != null) { preferences.SaveToFile(false); } } catch (Exception ex) { Instance? log = _log; if (log != null) { log.Warning("WristHub call volume preference will retry saving: " + ex.GetBaseException().Message); } } } private static void ReleaseVisuals() { if ((Object)(object)_controlsRoot != (Object)null) { try { Object.Destroy((Object)(object)_controlsRoot); } catch { } } _controlsRoot = null; _boundVisualRoot = null; _volumeStatus = null; _inviteStatus = null; _intakeOutline = null; _lastVolumePercent = int.MinValue; _lastMuteState = -1; _lastCameraMode = -1; _lastSpeakerState = -1; _boundCallId = string.Empty; _inviteResultState = 0; _inviteStatusUntil = 0f; for (int i = 0; i < Buttons.Length; i++) { Buttons[i] = default(ButtonVisual); } ClearTouchState(); } private static void ClearTouchState() { for (int i = 0; i < Buttons.Length; i++) { for (int j = 0; j < 2; j++) { WasInside[i, j] = false; } } } private static void DestroyMaterial(ref Material? material) { if ((Object)(object)material != (Object)null) { try { Object.Destroy((Object)(object)material); } catch { } } material = null; } } internal static class Dev49FriendsAvatarPatch { private const string HarmonyId = "WristHub.Build49.FriendsAvatarRefresh"; private const float AvatarRefreshCooldownSeconds = 3f; private static readonly FieldInfo RuntimeField = typeof(BoneHubAvatarBrowser).GetField("_runtime", BindingFlags.Instance | BindingFlags.NonPublic); private static Harmony? _harmony; private static Instance? _log; private static float _nextAvatarRefreshAt; private static float _nextFailureLogAt; internal static void Initialize(Instance log) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown _log = log; _nextAvatarRefreshAt = 0f; _harmony = new Harmony("WristHub.Build49.FriendsAvatarRefresh"); PatchAvatarEntry("Open"); PatchAvatarEntry("OpenSearch"); PatchAvatarEntry("OpenAvatarsFromOs"); } internal static void OnSceneChanged() { _nextAvatarRefreshAt = 0f; } internal static void Shutdown() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _harmony = null; _nextAvatarRefreshAt = 0f; _log = null; } private static void PatchAvatarEntry(string methodName) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown MethodInfo methodInfo = AccessTools.Method(typeof(BoneHubAvatarBrowser), methodName, Type.EmptyTypes, (Type[])null) ?? throw new MissingMethodException(typeof(BoneHubAvatarBrowser).FullName, methodName); _harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Dev49FriendsAvatarPatch), "AvatarEntryPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } private static void AvatarEntryPostfix(BoneHubAvatarBrowser __instance) { if (Time.unscaledTime < _nextAvatarRefreshAt) { return; } _nextAvatarRefreshAt = Time.unscaledTime + 3f; try { object? value = RuntimeField.GetValue(__instance); BoneHubRuntime val = (BoneHubRuntime)((value is BoneHubRuntime) ? value : null); if (val != null) { val.RefreshLocalLibrary(); } } catch (Exception ex) { if (!(Time.unscaledTime < _nextFailureLogAt)) { _nextFailureLogAt = Time.unscaledTime + 15f; Instance? log = _log; if (log != null) { log.Warning("WristHub will retry the downloaded-avatar refresh safely: " + ex.GetBaseException().Message); } } } } } internal static class Dev49FusionPortalPatch { private const string HarmonyId = "WristHub.Build49.FusionPortalRepair"; private static Harmony? _harmony; [ThreadStatic] private static int _portalTraversalDepth; internal static void Initialize(Instance _) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Expected O, but got Unknown //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Expected O, but got Unknown //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Expected O, but got Unknown //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Expected O, but got Unknown //IL_01b0: Expected O, but got Unknown //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Expected O, but got Unknown _harmony = new Harmony("WristHub.Build49.FusionPortalRepair"); MethodInfo methodInfo = AccessTools.Method(typeof(FusionPortalBridge), "JoinServer", new Type[3] { typeof(string), typeof(Instance), typeof(ulong) }, (Type[])null) ?? throw new MissingMethodException(typeof(FusionPortalBridge).FullName, "JoinServer"); MethodInfo methodInfo2 = AccessTools.Method(typeof(FusionPortalBridge), "JoinSocialServer", new Type[2] { typeof(string), typeof(Instance) }, (Type[])null) ?? throw new MissingMethodException(typeof(FusionPortalBridge).FullName, "JoinSocialServer"); MethodInfo methodInfo3 = AccessTools.Method(typeof(BoneHubAvatarBrowser), "BeginFusionServerJoin", (Type[])null, (Type[])null) ?? throw new MissingMethodException(typeof(BoneHubAvatarBrowser).FullName, "BeginFusionServerJoin"); MethodInfo methodInfo4 = AccessTools.Method(typeof(PartyPortalRelayPolicy), "CanPresentInSourceScope", (Type[])null, (Type[])null) ?? throw new MissingMethodException(typeof(PartyPortalRelayPolicy).FullName, "CanPresentInSourceScope"); _harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Dev49FusionPortalPatch), "JoinServerPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); _harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(Dev49FusionPortalPatch), "JoinSocialServerPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); _harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(Dev49FusionPortalPatch), "PortalTraversalPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Dev49FusionPortalPatch), "PortalTraversalFinalizer", (Type[])null), (HarmonyMethod)null); _harmony.Patch((MethodBase)methodInfo4, (HarmonyMethod)null, new HarmonyMethod(typeof(Dev49FusionPortalPatch), "CanPresentPortalPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } internal static void Tick() { } internal static void OnSceneChanged() { } internal static void Shutdown() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _harmony = null; _portalTraversalDepth = 0; } private static void PortalTraversalPrefix() { _portalTraversalDepth++; } private static Exception? PortalTraversalFinalizer(Exception? __exception) { if (_portalTraversalDepth > 0) { _portalTraversalDepth--; } return __exception; } private static void CanPresentPortalPostfix(PortalLinkState? state, bool matchesCurrentLevel, long nowUnixSeconds, ref bool __result) { if (!__result && !NetworkInfo.HasServer) { __result = state != null && state.IsPartyPortal && state.PlacementClaimed && matchesCurrentLevel && nowUnixSeconds >= 0 && !state.IsExpired(nowUnixSeconds) && FusionServerEntry.IsValidCode(state.DestinationServerCode); } } private static bool JoinServerPrefix(string code, Instance log, ulong lobbyId, ref bool __result) { if (!Dev49FusionPortalRepairPolicy.ShouldUseObservedJoin(NetworkInfo.HasServer)) { return true; } bool flag = _portalTraversalDepth > 0; __result = FusionPortalBridge.BeginServerSwitch(code, log, lobbyId, false, false, false); if (__result) { log.Msg(flag ? "WristHub submitted the offline Party Portal destination exactly once through Fusion." : "WristHub began the offline Fusion handoff only after JOIN."); } return false; } private static bool JoinSocialServerPrefix(string code, Instance log, ref bool __result) { if (!Dev49FusionPortalRepairPolicy.ShouldUseObservedJoin(NetworkInfo.HasServer)) { return true; } __result = FusionPortalBridge.BeginServerSwitch(code, log, 0uL, false, false, true); if (__result) { log.Msg("WristHub kept the offline Friend lobby JOIN through Fusion login with one guarded recovery."); } return false; } } internal static class Dev49FusionServerEditorPatch { private const string HarmonyId = "WristHub.Build49.FusionServerEditor"; private static readonly Type BrowserType = typeof(BoneHubAvatarBrowser); private static readonly FieldInfo HomePageField = AccessTools.Field(BrowserType, "_fusionHomePage"); private static readonly FieldInfo HostingPageField = AccessTools.Field(BrowserType, "_fusionHostingPage"); private static readonly FieldInfo HostingStatusField = AccessTools.Field(BrowserType, "_fusionHostingStatus"); private static Harmony? _harmony; private static Instance? _log; private static MethodInfo? _pushSettingsUpdate; private static GameObject? _cachedHomePage; private static GameObject? _cachedHostingPage; private static Component? _homeActionLabel; private static Component? _hostingTitle; private static Component? _hostingActionLabel; internal static void Initialize(Instance log) { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Expected O, but got Unknown //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Expected O, but got Unknown //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Expected O, but got Unknown _log = log; Type type = (from assembly in AppDomain.CurrentDomain.GetAssemblies() select assembly.GetType("LabFusion.Preferences.Server.SavedServerSettings", throwOnError: false)).FirstOrDefault((Type type2) => type2 != null) ?? throw new TypeLoadException("LabFusion.Preferences.Server.SavedServerSettings"); _pushSettingsUpdate = type.GetMethod("PushSettingsUpdate", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null) ?? throw new MissingMethodException(type.FullName, "PushSettingsUpdate"); _harmony = new Harmony("WristHub.Build49.FusionServerEditor"); MethodInfo methodInfo = AccessTools.Method(BrowserType, "RefreshFusionHome", (Type[])null, (Type[])null) ?? throw new MissingMethodException(BrowserType.FullName, "RefreshFusionHome"); MethodInfo methodInfo2 = AccessTools.Method(BrowserType, "RefreshFusionHostingPage", (Type[])null, (Type[])null) ?? throw new MissingMethodException(BrowserType.FullName, "RefreshFusionHostingPage"); MethodInfo methodInfo3 = AccessTools.Method(BrowserType, "StartFusionLobby", (Type[])null, (Type[])null) ?? throw new MissingMethodException(BrowserType.FullName, "StartFusionLobby"); _harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Dev49FusionServerEditorPatch), "RefreshHomePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); _harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(Dev49FusionServerEditorPatch), "RefreshHostingPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); _harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(Dev49FusionServerEditorPatch), "StartLobbyPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } internal static void OnSceneChanged() { ClearUiCache(); } internal static void Shutdown() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _harmony = null; _pushSettingsUpdate = null; ClearUiCache(); _log = null; } private static void RefreshHomePostfix(object __instance) { CacheLabels(__instance); SetText(_homeActionLabel, IsEditingLiveServer() ? "EDIT SERVER" : "CREATE LOBBY"); } private static void RefreshHostingPostfix(object __instance) { CacheLabels(__instance); bool flag = IsEditingLiveServer(); SetText(_hostingTitle, flag ? "EDIT CURRENT SERVER" : "CREATE FUSION LOBBY"); SetText(_hostingActionLabel, flag ? "APPLY LIVE" : "START LOBBY"); } private static bool StartLobbyPrefix(object __instance) { //IL_0072: 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) if (!IsEditingLiveServer()) { return true; } CacheLabels(__instance); try { _pushSettingsUpdate.Invoke(null, null); SetStatus(__instance, "SERVER SETTINGS UPDATED LIVE", new Color(0.32f, 0.9f, 0.62f, 1f)); Instance? log = _log; if (log != null) { log.Msg("WristHub pushed the host's edited Fusion server information live."); } } catch (Exception ex) { SetStatus(__instance, "SERVER UPDATE FAILED • RETRY", new Color(1f, 0.28f, 0.39f, 1f)); Instance? log2 = _log; if (log2 != null) { log2.Warning("WristHub could not push the edited Fusion server information: " + ex.GetBaseException().Message); } } return false; } private static bool IsEditingLiveServer() { try { return NetworkInfo.HasServer && NetworkInfo.IsHost; } catch { return false; } } private static void CacheLabels(object instance) { object? value = HomePageField.GetValue(instance); GameObject val = (GameObject)((value is GameObject) ? value : null); if ((Object)(object)val != (Object)(object)_cachedHomePage) { _cachedHomePage = val; _homeActionLabel = FindText(val, "CREATE LOBBY", "EDIT SERVER"); } object? value2 = HostingPageField.GetValue(instance); GameObject val2 = (GameObject)((value2 is GameObject) ? value2 : null); if ((Object)(object)val2 != (Object)(object)_cachedHostingPage) { _cachedHostingPage = val2; _hostingTitle = FindText(val2, "CREATE FUSION LOBBY", "EDIT CURRENT SERVER"); _hostingActionLabel = FindText(val2, "START LOBBY", "APPLY LIVE"); } } private static Component? FindText(GameObject? root, params string[] expected) { if ((Object)(object)root == (Object)null) { return null; } try { foreach (Component componentsInChild in root.GetComponentsInChildren(true)) { if ((Object)(object)componentsInChild == (Object)null) { continue; } PropertyInfo property = ((object)componentsInChild).GetType().GetProperty("text", BindingFlags.Instance | BindingFlags.Public); if ((object)property != null && property.CanRead && property.CanWrite && !(property.PropertyType != typeof(string))) { string current2 = property.GetValue(componentsInChild) as string; if (expected.Any((string value) => string.Equals(value, current2, StringComparison.OrdinalIgnoreCase))) { return componentsInChild; } } } } catch { } return null; } private static void SetStatus(object instance, string text, Color color) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) object? value = HostingStatusField.GetValue(instance); object? component = ((value is Component) ? value : null); SetText((Component?)component, text); SetColor((Component?)component, color); } private static void SetText(Component? component, string value) { try { ((object)component)?.GetType().GetProperty("text")?.SetValue(component, value); } catch { } } private static void SetColor(Component? component, Color value) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) try { ((object)component)?.GetType().GetProperty("color")?.SetValue(component, value); } catch { } } private static void ClearUiCache() { _cachedHomePage = null; _cachedHostingPage = null; _homeActionLabel = null; _hostingTitle = null; _hostingActionLabel = null; } } internal static class Dev49GripRecoveryPatch { private readonly record struct HandReleaseState(int HandId, float ReleasedSince); private const string HarmonyId = "WristHub.Build49.GripRecovery"; private const float MaintenanceIntervalSeconds = 0.1f; private const float ReleasedRecoveryDelaySeconds = 0.25f; private const float ReleasedGripForce = 0.1f; private static Harmony? _harmony; private static Instance? _log; private static float _nextMaintenanceAt; private static HandReleaseState _left; private static HandReleaseState _right; private static int _reportedHoverFailure; private static int _reportedDestroyFailure; private static int _reportedRecovery; internal static void Initialize(Instance log) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Expected O, but got Unknown _log = log; ResetState(); _harmony = new Harmony("WristHub.Build49.GripRecovery"); MethodInfo methodInfo = AccessTools.Method(typeof(Hand), "UpdateHovering", (Type[])null, (Type[])null) ?? throw new MissingMethodException(typeof(Hand).FullName, "UpdateHovering"); MethodInfo methodInfo2 = AccessTools.Method(typeof(Grip), "OnDestroy", (Type[])null, (Type[])null) ?? throw new MissingMethodException(typeof(Grip).FullName, "OnDestroy"); _harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Dev49GripRecoveryPatch), "UpdateHoveringFinalizer", (Type[])null), (HarmonyMethod)null); _harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Dev49GripRecoveryPatch), "GripOnDestroyFinalizer", (Type[])null), (HarmonyMethod)null); } internal static void Tick() { if (!(Time.unscaledTime < _nextMaintenanceAt)) { _nextMaintenanceAt = Time.unscaledTime + 0.1f; ObserveReleasedHand(Player.LeftHand, ref _left); ObserveReleasedHand(Player.RightHand, ref _right); } } internal static void OnSceneChanged() { ResetState(); } internal static void Shutdown() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _harmony = null; ResetState(); _log = null; } private static Exception? UpdateHoveringFinalizer(Hand __instance, Exception? __exception) { if (!IsNullReference(__exception)) { return __exception; } RepairReleasedHand(__instance, requireReleasedInput: true, provenFault: true); if (Interlocked.Exchange(ref _reportedHoverFailure, 1) == 0) { Instance? log = _log; if (log != null) { log.Msg("WristHub recovered a hand hover pass interrupted by a destroyed preview grip."); } } return null; } private static Exception? GripOnDestroyFinalizer(Exception? __exception) { if (!IsNullReference(__exception) || !__exception.ToString().Contains("MarrowEntity.UnregisterEventHandler", StringComparison.Ordinal)) { return __exception; } if (Interlocked.Exchange(ref _reportedDestroyFailure, 1) == 0) { Instance? log = _log; if (log != null) { log.Msg("WristHub contained malformed preview-grip cleanup before it could leave a hand locked."); } } return null; } private static void ObserveReleasedHand(Hand? hand, ref HandReleaseState state) { if ((Object)(object)hand == (Object)null) { state = default(HandReleaseState); return; } int instanceID; try { instanceID = ((Object)hand).GetInstanceID(); } catch { state = default(HandReleaseState); return; } if (instanceID == 0 || state.HandId != instanceID) { state = new HandReleaseState(instanceID, 0f); return; } float num = ReadGripForce(hand); if (!float.IsFinite(num) || num > 0.1f) { state = state with { ReleasedSince = 0f }; } else if (state.ReleasedSince <= 0f) { state = state with { ReleasedSince = Time.unscaledTime }; } else if (!(Time.unscaledTime - state.ReleasedSince < 0.25f)) { RepairReleasedHand(hand, requireReleasedInput: false, provenFault: false); } } private static void RepairReleasedHand(Hand? hand, bool requireReleasedInput, bool provenFault) { if ((Object)(object)hand == (Object)null) { return; } if (requireReleasedInput) { float num = ReadGripForce(hand); if (!float.IsFinite(num) || num > 0.1f) { return; } } bool flag = false; bool flag2 = false; try { GameObject currentAttachedGO = hand.m_CurrentAttachedGO; if (!Alive((Object?)(object)currentAttachedGO)) { if (currentAttachedGO != null) { flag = (flag2 = true); } hand.m_CurrentAttachedGO = null; } } catch { } bool flag3 = false; try { HandReciever attachedReceiver_k__BackingField = hand._AttachedReceiver_k__BackingField; flag3 = Alive((Object?)(object)attachedReceiver_k__BackingField); if (!flag3) { if (attachedReceiver_k__BackingField != null) { flag = (flag2 = true); } hand._AttachedReceiver_k__BackingField = null; } } catch { } bool flag4 = false; try { flag4 = Alive((Object?)(object)hand.m_CurrentAttachedGO); } catch { } if (flag3 || flag4 || (!provenFault && !flag2)) { return; } try { if (!hand.hoverLocked) { return; } hand.hoverLocked = false; flag = true; } catch { } if (flag && Interlocked.Exchange(ref _reportedRecovery, 1) == 0) { Instance? log = _log; if (log != null) { log.Msg("WristHub released a stale hand hover lock after the physical grip returned to neutral."); } } } private static float ReadGripForce(Hand hand) { try { BaseController controller = hand.Controller; return (controller != null) ? controller.GetGripForce() : float.NaN; } catch { return float.NaN; } } private static bool Alive(Object? value) { try { return value != (Object)null; } catch { return false; } } private static bool IsNullReference(Exception? exception) { if (exception == null) { return false; } if (exception is NullReferenceException) { return true; } try { return exception.ToString().Contains("System.NullReferenceException", StringComparison.Ordinal); } catch { return false; } } private static void ResetState() { _left = default(HandReleaseState); _right = default(HandReleaseState); _nextMaintenanceAt = 0f; _reportedHoverFailure = 0; _reportedDestroyFailure = 0; _reportedRecovery = 0; } } internal static class Dev49LagGuardPatch { private const string HarmonyId = "WristHub.Build49.LagGuard"; private static Harmony? _harmony; private static PropertyInfo? _targetTransform; private static Instance? _log; private static int _reported; internal static void Initialize(Instance log) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown _log = log; _reported = 0; Type? typeFromHandle = typeof(SmoothFollower); _targetTransform = AccessTools.Property(typeFromHandle, "targetTransform"); MethodInfo methodInfo = AccessTools.Method(typeFromHandle, "MoveCameraUpdate", (Type[])null, (Type[])null); if (!(_targetTransform == null) && !(methodInfo == null)) { _harmony = new Harmony("WristHub.Build49.LagGuard"); _harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Dev49LagGuardPatch), "MoveCameraPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } internal static void Shutdown() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _harmony = null; _targetTransform = null; _reported = 0; _log = null; } private static bool MoveCameraPrefix(object __instance) { try { object? obj = _targetTransform?.GetValue(__instance); Transform val = (Transform)((obj is Transform) ? obj : null); if (val != null && (Object)(object)val != (Object)null) { return true; } if (Interlocked.Exchange(ref _reported, 1) == 0) { Instance? log = _log; if (log != null) { log.Warning("WristHub paused a camera follower with no target instead of letting it throw every frame."); } } return false; } catch { return true; } } } internal static class Dev49PreviewPullPatch { internal static void Initialize(Instance log) { log.Msg("WristHub Preview Pull is using the native first-release detach path."); } internal static void Shutdown() { } } internal static class Dev49SearchTouchPatch { private const string HarmonyId = "WristHub.Build49.SearchTouch"; private const int PageSize = 100; private const int MaximumPages = 10; private static readonly FieldInfo InputRearmField = AccessTools.Field(typeof(BoneHubAvatarBrowser), "_inputRearm"); private static Harmony? _harmony; private static Instance? _log; private static int _failureReported; [ThreadStatic] private static int _insidePagedSearch; internal static void Initialize(Instance log) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Expected O, but got Unknown //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Expected O, but got Unknown _log = log; _failureReported = 0; _harmony = new Harmony("WristHub.Build49.SearchTouch"); MethodInfo methodInfo = AccessTools.Method(typeof(BoneHubService), "SearchAsync", new Type[2] { typeof(ModSearchRequest), typeof(CancellationToken) }, (Type[])null) ?? throw new MissingMethodException(typeof(BoneHubService).FullName, "SearchAsync"); MethodInfo methodInfo2 = AccessTools.Method(typeof(BoneHubAvatarBrowser), "ResetTouchButtons", (Type[])null, (Type[])null) ?? throw new MissingMethodException(typeof(BoneHubAvatarBrowser).FullName, "ResetTouchButtons"); MethodInfo methodInfo3 = AccessTools.Method(typeof(BoneHubAvatarBrowser), "ReleaseTouchCapture", (Type[])null, (Type[])null) ?? throw new MissingMethodException(typeof(BoneHubAvatarBrowser).FullName, "ReleaseTouchCapture"); _harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Dev49SearchTouchPatch), "SearchPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); HarmonyMethod val = new HarmonyMethod(typeof(Dev49SearchTouchPatch), "RequireReleasePostfix", (Type[])null); _harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); _harmony.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } internal static void Shutdown() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _harmony = null; _insidePagedSearch = 0; _failureReported = 0; _log = null; } private static bool SearchPrefix(BoneHubService __instance, ModSearchRequest request, CancellationToken cancellationToken, ref Task> __result) { if (_insidePagedSearch != 0 || request.Offset != 0 || string.IsNullOrWhiteSpace(request.Query) || !IsCompleteLibraryTag(request.Tag)) { return true; } __result = SearchEveryPageAsync(__instance, request, cancellationToken); return false; } private static async Task> SearchEveryPageAsync(BoneHubService service, ModSearchRequest request, CancellationToken cancellationToken) { List results = new List(100); HashSet seen = new HashSet(); int reportedTotal = 0; for (int pageIndex = 0; pageIndex < 10; pageIndex++) { cancellationToken.ThrowIfCancellationRequested(); int offset = pageIndex * 100; _insidePagedSearch++; Task> task; try { ModSearchRequest obj = request.$(); obj.set_Offset(offset); obj.set_Limit(100); task = service.SearchAsync(obj, cancellationToken); } finally { _insidePagedSearch--; } ModIoPage val; try { val = await task.ConfigureAwait(continueOnCapturedContext: false); } catch when (results.Count > 0 && !cancellationToken.IsCancellationRequested) { break; } reportedTotal = Math.Max(reportedTotal, val.ResultTotal); foreach (ModIoMod datum in val.Data) { if (datum.Id > 0 && seen.Add(datum.Id)) { results.Add(datum); } } if (val.Data.Count < 100 || (reportedTotal > 0 && offset + val.Data.Count >= reportedTotal)) { break; } } ModIoPage obj3 = new ModIoPage(); obj3.set_Data(results); obj3.set_ResultCount(results.Count); obj3.set_ResultOffset(0); obj3.set_ResultLimit(results.Count); obj3.set_ResultTotal(Math.Max(reportedTotal, results.Count)); return obj3; } private static bool IsCompleteLibraryTag(string? tag) { if (!string.Equals(tag, "Avatar", StringComparison.OrdinalIgnoreCase)) { return string.Equals(tag, "Spawnable", StringComparison.OrdinalIgnoreCase); } return true; } private static void RequireReleasePostfix(BoneHubAvatarBrowser __instance) { try { object? value = InputRearmField.GetValue(__instance); SurfaceInputRearmGate val = (SurfaceInputRearmGate)((value is SurfaceInputRearmGate) ? value : null); if (val != null) { val.Require(); } } catch (Exception ex) { if (Interlocked.Exchange(ref _failureReported, 1) == 0) { Instance? log = _log; if (log != null) { log.Warning("WristHub touch rearm recovered safely: " + ex.GetBaseException().GetType().Name); } } } } } internal static class Dev49SoundboardAudioPatch { private sealed class PcmLane { private readonly short[] _samples; private readonly int[] _packets; private int _sampleRead; private int _sampleWrite; private int _sampleCount; private int _packetRead; private int _packetWrite; private int _packetCount; internal int FrontPacketLength { get { if (_packetCount != 0) { return _packets[_packetRead]; } return 0; } } internal PcmLane(int sampleCapacity, int packetCapacity) { _samples = new short[sampleCapacity]; _packets = new int[packetCapacity]; } internal int Enqueue(short[] source, int count) { int num = 0; while (_packetCount > 0 && (_samples.Length - _sampleCount < count || _packetCount == _packets.Length)) { int frontPacketLength = FrontPacketLength; Discard(frontPacketLength); num += frontPacketLength; } CopyInto(source, count); _packets[_packetWrite] = count; _packetWrite = (_packetWrite + 1) % _packets.Length; _packetCount++; return num; } internal int Read(short[] destination, int count) { int num = Math.Min(count, _sampleCount); CopyFrom(destination, num); Discard(num); return num; } internal void CopyFront(short[] destination, int count) { CopyFrom(destination, count); } internal void Discard(int count) { int num = Math.Min(count, _sampleCount); while (num > 0 && _packetCount > 0) { int num2 = _packets[_packetRead]; int num3 = Math.Min(num, num2); num2 -= num3; num -= num3; _sampleRead = (_sampleRead + num3) % _samples.Length; _sampleCount -= num3; if (num2 == 0) { _packets[_packetRead] = 0; _packetRead = (_packetRead + 1) % _packets.Length; _packetCount--; } else { _packets[_packetRead] = num2; } } } internal void Clear() { Array.Clear(_packets); _sampleRead = 0; _sampleWrite = 0; _sampleCount = 0; _packetRead = 0; _packetWrite = 0; _packetCount = 0; } private void CopyInto(short[] source, int count) { int num = Math.Min(count, _samples.Length - _sampleWrite); Array.Copy(source, 0, _samples, _sampleWrite, num); if (count > num) { Array.Copy(source, num, _samples, 0, count - num); } _sampleWrite = (_sampleWrite + count) % _samples.Length; _sampleCount += count; } private void CopyFrom(short[] destination, int count) { int num = Math.Min(count, _samples.Length - _sampleRead); Array.Copy(_samples, _sampleRead, destination, 0, num); if (count > num) { Array.Copy(_samples, 0, destination, num, count - num); } } } private const string HarmonyId = "WristHub.Build49.SoundboardAudio"; private const int MaximumPcmSamplesPerPacket = 16384; private const int MaximumEncodedPacketBytes = 131072; private const int QueuedPacketCapacity = 6; private const int LocalPrebufferMilliseconds = 3000; private const double ActiveSpeechRmsThreshold = 0.012; private const double ActiveSpeechPeakThreshold = 0.05; private const double ActiveSpeechSoundboardGain = 0.62; private const double QuietSoundboardGain = 0.78; private const int MixedLimiterMagnitude = 32111; private static readonly object ResolveGate = new object(); private static readonly object LaneGate = new object(); private static readonly PcmLane Lane = new PcmLane(16384, 6); private static readonly short[] MixScratch = new short[16384]; private static readonly Type ExactBridgeType = typeof(LobbySoundboardRuntime).Assembly.GetType("BoneHub.Mod.FusionVoiceSoundboardBridge", throwOnError: true); private static Harmony? _harmony; private static Instance? _log; private static Func? _encode; private static Func? _isMuted; private static Func? _serverVoiceEnabled; private static short[] _syntheticPacket = Array.Empty(); private static bool _resolveAttempted; private static bool _voiceLaneInstalled; private static int _encodeBusy; private static int _failureReported; private static long _droppedSamples; private static double _currentMixGain = 0.78; private static bool _platformOwnsVoiceLane; [ThreadStatic] private static int _insideVoiceUpdate; [ThreadStatic] private static int _skipEncodeMix; internal static void Initialize(Instance log) { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Expected O, but got Unknown //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Expected O, but got Unknown //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Expected O, but got Unknown //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Expected O, but got Unknown _log = log; if (ExactBridgeType.GetMethod("TryQueue", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[3] { typeof(short[]), typeof(int), typeof(string).MakeByRefType() }, null) != null) { _platformOwnsVoiceLane = true; _resolveAttempted = true; Instance? log2 = _log; if (log2 != null) { log2.Msg("WristHub Soundboard is using the universal synchronized audio lane and native prebuffer."); } return; } _harmony = new Harmony("WristHub.Build49.SoundboardAudio"); MethodInfo method = typeof(LobbySoundboardRuntime).GetMethod("EncodeVoicePacket", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(short[]) }, null); MethodInfo method2 = ExactBridgeType.GetMethod("TrySendEncoded", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2] { typeof(byte[]), typeof(string).MakeByRefType() }, null); MethodInfo methodInfo = AccessTools.Method(typeof(LobbySoundboardRuntime), "Stop", Type.EmptyTypes, (Type[])null) ?? throw new MissingMethodException(typeof(LobbySoundboardRuntime).FullName, "Stop"); MethodInfo methodInfo2 = AccessTools.Method(typeof(QuestSoundboardDecodePolicy), "IsStreamReady", (Type[])null, (Type[])null) ?? throw new MissingMethodException(typeof(QuestSoundboardDecodePolicy).FullName, "IsStreamReady"); _harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Dev49SoundboardAudioPatch), "ClearPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); _harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(Dev49SoundboardAudioPatch), "StreamReadyPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); if (method == null || method2 == null) { _platformOwnsVoiceLane = true; _resolveAttempted = true; Instance? log3 = _log; if (log3 != null) { log3.Msg("WristHub Soundboard is using the universal synchronized audio lane."); } } else { _harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(Dev49SoundboardAudioPatch), "CapturePcmPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); _harmony.Patch((MethodBase)method2, new HarmonyMethod(typeof(Dev49SoundboardAudioPatch), "SendEncodedPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); TryInstallVoiceLane(); } } internal static void Tick() { if (!_platformOwnsVoiceLane && !_voiceLaneInstalled && !_resolveAttempted) { TryInstallVoiceLane(); } } internal static void OnSceneChanged() { ClearQueuedAudio(); } internal static void Shutdown() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _harmony = null; ClearQueuedAudio(); _encode = null; _isMuted = null; _serverVoiceEnabled = null; _resolveAttempted = false; _voiceLaneInstalled = false; _platformOwnsVoiceLane = false; _failureReported = 0; _log = null; } private static void CapturePcmPrefix(short[] samples) { if (!_voiceLaneInstalled || samples == null || samples.Length == 0 || samples.Length > 16384) { return; } lock (LaneGate) { int num = Lane.Enqueue(samples, samples.Length); if (num > 0) { Interlocked.Add(ref _droppedSamples, num); } } } private static bool SendEncodedPrefix(ref string reason, ref bool __result) { if (!_voiceLaneInstalled) { return true; } reason = string.Empty; __result = true; return false; } private static void ClearPostfix() { ClearQueuedAudio(); } private static void StreamReadyPostfix(int availableSamples, bool isComplete, int sampleRate, int channels, ref bool __result) { if (availableSamples >= 0 && sampleRate > 0 && channels > 0) { long num = Math.Min(2147483647L, (long)sampleRate * (long)channels * 3000 / 1000); __result = availableSamples >= num || (isComplete && availableSamples > 0); } } private static void TryInstallVoiceLane() { //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Expected O, but got Unknown //IL_01c1: Expected O, but got Unknown //IL_01c1: Expected O, but got Unknown //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Expected O, but got Unknown lock (ResolveGate) { if (_resolveAttempted || _harmony == null) { return; } _resolveAttempted = true; try { Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly assembly2) => string.Equals(assembly2.GetName().Name, "LabFusion", StringComparison.OrdinalIgnoreCase)); if (assembly == null) { _resolveAttempted = false; return; } Type type = assembly.GetType("LabFusion.Voice.VoiceConverter", throwOnError: false); Type type2 = assembly.GetType("LabFusion.Voice.Unity.UnityVoiceReceiver", throwOnError: false); Type type3 = assembly.GetType("LabFusion.Voice.VoiceInfo", throwOnError: false); MethodInfo methodInfo = type?.GetMethod("Encode", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(short[]) }, null); MethodInfo methodInfo2 = type2?.GetMethod("UpdateVoice", BindingFlags.Instance | BindingFlags.Public, null, new Type[1] { typeof(bool) }, null); if (!(methodInfo == null) && !(methodInfo2 == null) && !(type2?.GetField("_encodedData", BindingFlags.Instance | BindingFlags.NonPublic) == null) && !(type2.GetField("_hasVoiceActivity", BindingFlags.Instance | BindingFlags.NonPublic) == null)) { _encode = (Func)Delegate.CreateDelegate(typeof(Func), methodInfo); _isMuted = StaticBoolGetter(type3, "IsMuted"); _serverVoiceEnabled = StaticBoolGetter(type3, "ServerVoiceEnabled"); _harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(Dev49SoundboardAudioPatch), "EnterVoiceUpdatePrefix", (Type[])null), new HarmonyMethod(typeof(Dev49SoundboardAudioPatch), "CompleteVoiceUpdatePostfix", (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Dev49SoundboardAudioPatch), "ExitVoiceUpdateFinalizer", (Type[])null), (HarmonyMethod)null); _harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Dev49SoundboardAudioPatch), "MixIntoVoiceEncodePrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); _voiceLaneInstalled = true; Instance? log = _log; if (log != null) { log.Msg("WristHub Soundboard attached to Fusion's clean synchronized microphone lane."); } } } catch (Exception exception) { ReportOnce("WristHub Soundboard voice-lane setup will retry after restart: ", exception); } } } private static Func? StaticBoolGetter(Type? type, string name) { MethodInfo methodInfo = type?.GetProperty(name, BindingFlags.Static | BindingFlags.Public)?.GetGetMethod(); if (!(methodInfo == null)) { return (Func)Delegate.CreateDelegate(typeof(Func), methodInfo); } return null; } private static void EnterVoiceUpdatePrefix() { _insideVoiceUpdate = 1; } private static void MixIntoVoiceEncodePrefix(short[] __0) { if (_insideVoiceUpdate == 0 || _skipEncodeMix != 0 || __0 == null || __0.Length == 0) { return; } int num; lock (LaneGate) { num = Lane.Read(MixScratch, Math.Min(__0.Length, MixScratch.Length)); } if (num > 0) { double num2 = SelectTargetGain(__0); double currentMixGain = _currentMixGain; for (int i = 0; i < num; i++) { double num3 = ((double)i + 1.0) / (double)num; double value = currentMixGain + (num2 - currentMixGain) * num3; long value2 = __0[i] + (long)Math.Round((double)MixScratch[i] * Math.Clamp(value, 0.0, 1.0)); __0[i] = (short)Math.Clamp(value2, -32111L, 32111L); } _currentMixGain = num2; } } private static void CompleteVoiceUpdatePostfix(ref byte[] ____encodedData, ref bool ____hasVoiceActivity) { try { if (____hasVoiceActivity) { return; } int frontPacketLength; lock (LaneGate) { frontPacketLength = Lane.FrontPacketLength; } if (frontPacketLength <= 0 || !VoicePolicyAllowsQueuedAudio()) { return; } lock (LaneGate) { frontPacketLength = Lane.FrontPacketLength; if (frontPacketLength <= 0) { return; } if (_syntheticPacket.Length != frontPacketLength) { _syntheticPacket = new short[frontPacketLength]; } Lane.CopyFront(_syntheticPacket, frontPacketLength); } _skipEncodeMix++; try { if (!TryEncode(_syntheticPacket, out byte[] encoded)) { return; } ____encodedData = encoded; ____hasVoiceActivity = true; } finally { _skipEncodeMix--; } lock (LaneGate) { Lane.Discard(frontPacketLength); } _currentMixGain = 0.78; } catch (Exception exception) { ReportOnce("WristHub Soundboard recovered its Fusion voice lane: ", exception); } finally { _insideVoiceUpdate = 0; } } private static Exception? ExitVoiceUpdateFinalizer(Exception? __exception) { _insideVoiceUpdate = 0; return __exception; } private static bool VoicePolicyAllowsQueuedAudio() { try { if (!FusionPortalBridge.IsConnected || (_serverVoiceEnabled != null && !_serverVoiceEnabled()) || (_isMuted != null && _isMuted())) { ClearQueuedAudio(); return false; } return true; } catch { ClearQueuedAudio(); return false; } } private static bool TryEncode(short[] samples, out byte[] encoded) { encoded = Array.Empty(); Func encode = _encode; if (encode == null || samples.Length == 0 || samples.Length > 16384 || Interlocked.CompareExchange(ref _encodeBusy, 1, 0) != 0) { return false; } try { byte[] array = encode(samples); if (array == null || array.Length == 0 || array.Length > 131072) { return false; } encoded = array; return true; } finally { Volatile.Write(ref _encodeBusy, 0); } } private static double SelectTargetGain(short[] microphone) { if (microphone.Length == 0) { return 0.78; } double num = 0.0; int num2 = 0; foreach (short num3 in microphone) { int val = Math.Abs((int)num3); num2 = Math.Max(num2, val); num += (double)num3 * (double)num3; } double num4 = Math.Sqrt(num / (double)microphone.Length) / 32767.0; double num5 = (double)num2 / 32767.0; if (!(num4 >= 0.012) && !(num5 >= 0.05)) { return 0.78; } return 0.62; } private static void ClearQueuedAudio() { lock (LaneGate) { Lane.Clear(); } Interlocked.Exchange(ref _droppedSamples, 0L); _currentMixGain = 0.78; } private static void ReportOnce(string prefix, Exception exception) { if (Interlocked.Exchange(ref _failureReported, 1) == 0) { Instance? log = _log; if (log != null) { log.Warning(prefix + exception.GetBaseException().GetType().Name); } } } } public static class ExtensionRuntime { private static Instance? _log; private static long _nextFailureLogAt; private static int _initialized; public static void Initialize(Instance log) { _log = log; if (Interlocked.Exchange(ref _initialized, 1) != 0) { return; } try { Dev49CameraPatch.Initialize(log); Dev49CallCameraControls.Initialize(log); Dev49FusionPortalPatch.Initialize(log); Dev49FusionServerEditorPatch.Initialize(log); Dev49FriendsAvatarPatch.Initialize(log); Dev49SoundboardAudioPatch.Initialize(log); Dev49SearchTouchPatch.Initialize(log); Dev49LagGuardPatch.Initialize(log); Dev49PreviewPullPatch.Initialize(log); Dev49GripRecoveryPatch.Initialize(log); log.Msg("WristHub Build 49 stability layer active: adaptive video, physical call controls, throw-ready camera item handoff, full-world self preview, live Fusion server editing, traversal-only Fusion portals, complete search, release-safe touch, stable preview pulls, release-safe grip recovery, camera error quarantine, online-first Friends, and clean Soundboard audio."); } catch { try { Dev49GripRecoveryPatch.Shutdown(); } catch { } try { Dev49PreviewPullPatch.Shutdown(); } catch { } try { Dev49LagGuardPatch.Shutdown(); } catch { } try { Dev49SearchTouchPatch.Shutdown(); } catch { } try { Dev49SoundboardAudioPatch.Shutdown(); } catch { } try { Dev49FriendsAvatarPatch.Shutdown(); } catch { } try { Dev49FusionPortalPatch.Shutdown(); } catch { } try { Dev49FusionServerEditorPatch.Shutdown(); } catch { } try { Dev49CallCameraControls.Shutdown(); } catch { } try { Dev49CameraPatch.Shutdown(); } catch { } Interlocked.Exchange(ref _initialized, 0); throw; } } public static void OnUpdate() { if (Volatile.Read(in _initialized) == 0) { return; } try { Dev49CallCameraControls.Tick(); } catch (Exception ex) { long tickCount = Environment.TickCount64; if (tickCount >= _nextFailureLogAt) { _nextFailureLogAt = tickCount + 5000; Instance? log = _log; if (log != null) { log.Warning("WristHub call-camera controls recovered safely: " + ex.GetBaseException().Message); } } } try { Dev49FusionPortalPatch.Tick(); Dev49SoundboardAudioPatch.Tick(); Dev49CameraPatch.ObserveCall(); Dev49GripRecoveryPatch.Tick(); } catch (Exception ex2) { long tickCount2 = Environment.TickCount64; if (tickCount2 >= _nextFailureLogAt) { _nextFailureLogAt = tickCount2 + 5000; Instance? log2 = _log; if (log2 != null) { log2.Warning("WristHub Build 49 stability layer recovered safely: " + ex2.GetBaseException().Message); } } } finally { Dev49CameraWorkBudget.ResetForNextFrame(); } } public static void OnSceneChanged(int _, string __) { if (Volatile.Read(in _initialized) == 0) { return; } try { Dev49FusionPortalPatch.OnSceneChanged(); } catch { } try { Dev49FusionServerEditorPatch.OnSceneChanged(); } catch { } try { Dev49SoundboardAudioPatch.OnSceneChanged(); } catch { } try { Dev49FriendsAvatarPatch.OnSceneChanged(); } catch { } try { Dev49CallCameraControls.OnSceneChanged(); } catch { } try { Dev49GripRecoveryPatch.OnSceneChanged(); } catch { } } public static void Shutdown() { if (Interlocked.Exchange(ref _initialized, 0) != 0) { try { Dev49GripRecoveryPatch.Shutdown(); } catch { } try { Dev49PreviewPullPatch.Shutdown(); } catch { } try { Dev49LagGuardPatch.Shutdown(); } catch { } try { Dev49SearchTouchPatch.Shutdown(); } catch { } try { Dev49SoundboardAudioPatch.Shutdown(); } catch { } try { Dev49FriendsAvatarPatch.Shutdown(); } catch { } try { Dev49FusionPortalPatch.Shutdown(); } catch { } try { Dev49FusionServerEditorPatch.Shutdown(); } catch { } try { Dev49CallCameraControls.Shutdown(); } catch { } try { Dev49CameraPatch.Shutdown(); } catch { } _log = null; } } } public static class Dev49CameraWorkBudget { public static bool WorkedThisFrame { get; private set; } internal static void MarkHeavyMediaWork() { WorkedThisFrame = true; } internal static void ResetForNextFrame() { WorkedThisFrame = false; } } internal static class Dev49CameraPatch { private const int MaximumVideoBytesPerSecond = 1310720; private const int MaximumJpegBytes = 131072; private const string HarmonyId = "WristHub.Build49.CameraQuality"; private static readonly FieldInfo CameraField = typeof(WristHubVideoCallRuntime).GetField("_camera", BindingFlags.Static | BindingFlags.NonPublic); private static Harmony? _harmony; private static double _tokens; private static double _lastAt; private static string _callId = string.Empty; [ThreadStatic] private static int _reservedBytes; internal static void Initialize(Instance _) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Expected O, but got Unknown //IL_00be: Expected O, but got Unknown ResetBudget(); _harmony = new Harmony("WristHub.Build49.CameraQuality"); Type typeFromHandle = typeof(WristHubVideoCallRuntime); HarmonyMethod val = new HarmonyMethod(typeof(Dev49CameraPatch), "MarkHeavyWorkPrefix", (Type[])null); _harmony.Patch((MethodBase)AccessTools.Method(typeFromHandle, "CaptureReadbackStage", (Type[])null, (Type[])null), val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); _harmony.Patch((MethodBase)AccessTools.Method(typeFromHandle, "EncodeAndSendPendingReadback", (Type[])null, (Type[])null), val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); MethodInfo methodInfo = AccessTools.Method(typeof(WristHubWebRtcVoiceRuntime), "TrySendVideoFrameOwned", (Type[])null, (Type[])null); _harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Dev49CameraPatch), "VideoSendPrefix", (Type[])null), new HarmonyMethod(typeof(Dev49CameraPatch), "VideoSendPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } internal static void ObserveCall() { try { object? value = CameraField.GetValue(null); Camera val = (Camera)((value is Camera) ? value : null); if (val != null) { int num = CaptureWorldMask(); if (val.cullingMask != num) { val.cullingMask = num; } } } catch { } WristHubWebRtcCallSnapshot current = WristHubWebRtcVoiceRuntime.Current; string text = (current.IsActive ? current.CallId : string.Empty); if (!_callId.Equals(text, StringComparison.Ordinal)) { _callId = text; ResetBudget(); } } internal static void Shutdown() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _harmony = null; _callId = string.Empty; ResetBudget(); } private static void MarkHeavyWorkPrefix() { Dev49CameraWorkBudget.MarkHeavyMediaWork(); } private static int CaptureWorldMask() { int num = -1; int num2 = LayerMask.NameToLayer("UI"); if (num2 >= 0) { num &= ~(1 << num2); } return num; } private static bool VideoSendPrefix(byte[] jpegFrame, ref bool replacedPending, ref bool __result) { _reservedBytes = 0; int num = ((jpegFrame != null) ? jpegFrame.Length : 0); bool flag = ((num <= 0 || num > 131072) ? true : false); if (flag || !TryReserve(num)) { replacedPending = false; __result = false; return false; } _reservedBytes = num; return true; } private static void VideoSendPostfix(bool __result) { if (!__result && _reservedBytes > 0) { _tokens = Math.Min(1310720.0, _tokens + (double)_reservedBytes); } _reservedBytes = 0; } private static bool TryReserve(int bytes) { double unscaledTimeAsDouble = Time.unscaledTimeAsDouble; if (_lastAt <= 0.0) { _lastAt = unscaledTimeAsDouble; _tokens = 1310720.0; } else { double num = Math.Clamp(unscaledTimeAsDouble - _lastAt, 0.0, 1.0); _lastAt = unscaledTimeAsDouble; _tokens = Math.Min(1310720.0, _tokens + num * 1310720.0); } if (_tokens + 0.5 < (double)bytes) { return false; } _tokens -= bytes; return true; } private static void ResetBudget() { _tokens = 1310720.0; _lastAt = Time.unscaledTimeAsDouble; _reservedBytes = 0; } } }