Ejemplo n.º 1
0
        private static void SetSingleLayerOnMirrors(int layer, int state, VRC_MirrorReflection mirror)
        {
            foreach (var vrcMirrorReflection in UnityEngine.Object.FindObjectsOfType <VRC_MirrorReflection>()) //Only active
            {
                if (mirror == null || mirror == vrcMirrorReflection)
                {
                    switch (state)
                    {
                    case 0: vrcMirrorReflection.m_ReflectLayers = vrcMirrorReflection.m_ReflectLayers.value & ~(1 << layer); break;       //Remove Layer

                    case 1: vrcMirrorReflection.m_ReflectLayers = vrcMirrorReflection.m_ReflectLayers.value | (1 << layer); break;        //Add Layer

                    case 5: vrcMirrorReflection.m_ReflectLayers = -1; break;                                                              //All

                    case 6: vrcMirrorReflection.m_ReflectLayers = 0; break;                                                               //None

                    case 10: vrcMirrorReflection.m_ReflectLayers = -1 & ~UiLayer & ~UiMenuLayer & ~PlayerLocalLayer & ~UiCamLayer; break; //Full

                    case 11: vrcMirrorReflection.m_ReflectLayers = PlayerLayer | MirrorReflectionLayer; break;                            // Opt

                    default: MelonLogger.Msg(ConsoleColor.Red, "SetSingleLayerOnMirrors hit default case in Switch - Something is wrong"); break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override void Process(Object type, BuildTarget buildTarget)
        {
            base.Process(type, buildTarget);
#if VRC_SDK_VRCSDK2
            VRC_MirrorReflection component = (VRC_MirrorReflection)type;
#elif VRC_SDK_VRCSDK3
            VRCMirrorReflection component = (VRCMirrorReflection)type;
#endif
            switch (buildTarget)
            {
            case BuildTarget.StandaloneWindows64:
                component.m_DisablePixelLights   = DisablePixelLights.PC;
                component.TurnOffMirrorOcclusion = TurnOffMirrorOcclusion.PC;
                component.m_ReflectLayers        = ReflectLayers.PC;
                break;

            case BuildTarget.Android:
                component.m_DisablePixelLights   = DisablePixelLights.Quest;
                component.TurnOffMirrorOcclusion = TurnOffMirrorOcclusion.Quest;
                component.m_ReflectLayers        = ReflectLayers.Quest;
                break;

            default:
                break;
            }
        }
Ejemplo n.º 3
0
        //=========Mirror manager=========

        private void DoMirrorManager()
        {
            VRCPlayerApi.TrackingData trackingData = Networking.LocalPlayer.GetTrackingData(VRCPlayerApi.TrackingDataType.Head);

            Vector3 lookDirection = (trackingData.rotation * Vector3.forward).normalized;
            Ray     lookRay       = new Ray(trackingData.position, lookDirection);

            RaycastHit hit;

            if (Physics.Raycast(lookRay, out hit, maximumOpenDistance, 16, QueryTriggerInteraction.Collide))
            {
                GameObject           obj      = hit.collider.gameObject;
                VRC_MirrorReflection mirror   = (VRC_MirrorReflection)obj.GetComponent(typeof(VRC_MirrorReflection));
                Renderer             renderer = obj.GetComponent <Renderer>();
                if (mirror && renderer)
                {
                    if (activeMirrorRefelction != mirror)
                    {
                        SetActiveMirror(false);
                        activeMirrorRefelction = mirror;
                        activeMirrorRenderer   = renderer;
                        SetActiveMirror(true);
                    }
                    else
                    {
                        SetActiveMirror(!activeMirrorRefelction.enabled);
                    }
                    return;
                }
            }
            SetActiveMirror(false);
        }
        public override void Setup(Object type)
        {
            base.Setup(type);
            VRC_MirrorReflection component = (VRC_MirrorReflection)type;

            DisablePixelLights.Setup(component.m_DisablePixelLights);
            TurnOffMirrorOcclusion.Setup(component.TurnOffMirrorOcclusion);
            ReflectLayers.Setup(component.m_ReflectLayers);
        }
Ejemplo n.º 5
0
        public override void Setup(Object type)
        {
            base.Setup(type);
#if VRC_SDK_VRCSDK2
            VRC_MirrorReflection component = (VRC_MirrorReflection)type;
#elif VRC_SDK_VRCSDK3
            VRCMirrorReflection component = (VRCMirrorReflection)type;
#endif
            DisablePixelLights.Setup(component.m_DisablePixelLights);
            TurnOffMirrorOcclusion.Setup(component.TurnOffMirrorOcclusion);
            ReflectLayers.Setup(component.m_ReflectLayers);
        }
Ejemplo n.º 6
0
        // this is slightly rewritten code from VRCSDK
        // if only the game was still in IL so that transpiler harmony patches worked
        private static bool GetReflectionData(VRC_MirrorReflection __instance, Camera __0, ref VRC_MirrorReflection.ReflectionData __result)
        {
            try
            {
                var @this         = __instance;
                var currentCamera = __0;

                var reflections = @this._mReflections ??
                                  (@this._mReflections = new Dictionary <Camera, VRC_MirrorReflection.ReflectionData>());

                // TryGetValue crashes in unhollower 0.4
                var reflectionData = reflections.ContainsKey(currentCamera)
                    ? reflections[currentCamera]
                    : reflections[currentCamera] = new VRC_MirrorReflection.ReflectionData
                {
                    propertyBlock = new MaterialPropertyBlock()
                };

                if (@this._temporaryRenderTexture)
                {
                    RenderTexture.ReleaseTemporary(@this._temporaryRenderTexture);
                }
                if (reflectionData.texture[0])
                {
                    RenderTexture.ReleaseTemporary(reflectionData.texture[0]);
                }
                if (reflectionData.texture[1])
                {
                    RenderTexture.ReleaseTemporary(reflectionData.texture[1]);
                }

                int width;
                int height;

                if (ourAllMirrorsAuto || @this.mirrorResolution == VRC_MirrorReflection.Dimension.Auto)
                {
                    width  = Mathf.Min(currentCamera.pixelWidth, ourMaxEyeResolution);
                    height = Mathf.Min(currentCamera.pixelHeight, ourMaxEyeResolution);
                }
                else
                {
                    width = height = (int)@this.mirrorResolution;
                }

                var requestedMsaa = currentCamera.targetTexture?.antiAliasing ?? QualitySettings.antiAliasing;
                if (ourMirrorMsaa != 0)
                {
                    requestedMsaa = ourMsaaIsUpperLimit.Value
                        ? Mathf.Clamp(requestedMsaa, 1, ourMirrorMsaa)
                        : ourMirrorMsaa;
                }
                else
                {
                    requestedMsaa = Mathf.Clamp(requestedMsaa, 1, (int)@this.maximumAntialiasing);
                }
                @this._temporaryRenderTexture = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, requestedMsaa);
                reflectionData.texture[0]     = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, 1);
                reflectionData.propertyBlock.SetTexture(VRC_MirrorReflection._texturePropertyId[0], reflectionData.texture[0]);
                if (currentCamera.stereoEnabled)
                {
                    reflectionData.texture[1] = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, 1);
                    reflectionData.propertyBlock.SetTexture(VRC_MirrorReflection._texturePropertyId[1], reflectionData.texture[1]);
                }

                __result = reflectionData;
                return(false);
            }
            catch (Exception ex)
            {
                MelonLogger.Error("Exception happened in GetReflectionData override" + ex);
            }
            return(true);
        }
        // this is slightly rewritten code from VRCSDK
        // if only the game was still in IL so that transpiler harmony patches worked
        private static IntPtr GetReflectionData(IntPtr thisPtr, IntPtr currentCameraPtr)
        {
            try
            {
                var @this         = new VRC_MirrorReflection(thisPtr);
                var currentCamera = new Camera(currentCameraPtr);

                var reflections = @this._mReflections ??
                                  (@this._mReflections = new Dictionary <Camera, VRC_MirrorReflection.ReflectionData>());

                // TryGetValue crashes in unhollower 0.4
                var reflectionData = reflections.ContainsKey(currentCamera)
                    ? reflections[currentCamera]
                    : reflections[currentCamera] = new VRC_MirrorReflection.ReflectionData
                {
                    propertyBlock = new MaterialPropertyBlock()
                };

                if (@this._temporaryRenderTexture)
                {
                    RenderTexture.ReleaseTemporary(@this._temporaryRenderTexture);
                }
                if (reflectionData.texture[0])
                {
                    RenderTexture.ReleaseTemporary(reflectionData.texture[0]);
                }
                if (reflectionData.texture[1])
                {
                    RenderTexture.ReleaseTemporary(reflectionData.texture[1]);
                }

                int width;
                int height;

                if (ourAllMirrorsAuto || @this.mirrorResolution == VRC_MirrorReflection.Dimension.Auto)
                {
                    width  = Mathf.Min(currentCamera.pixelWidth, ourMaxEyeResolution);
                    height = Mathf.Min(currentCamera.pixelHeight, ourMaxEyeResolution);
                }
                else
                {
                    width = height = (int)@this.mirrorResolution;
                }

                int antiAliasing = ourMirrorMsaa == 0
                    ? Mathf.Clamp(1, QualitySettings.antiAliasing, (int)@this.maximumAntialiasing)
                    : ourMirrorMsaa;
                @this._temporaryRenderTexture = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, antiAliasing);
                reflectionData.texture[0]     = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, 1);
                reflectionData.propertyBlock.SetTexture(VRC_MirrorReflection._texturePropertyId[0], reflectionData.texture[0]);
                if (currentCamera.stereoEnabled)
                {
                    reflectionData.texture[1] = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, 1);
                    reflectionData.propertyBlock.SetTexture(VRC_MirrorReflection._texturePropertyId[1], reflectionData.texture[1]);
                }

                return(reflectionData.Pointer);
            }
            catch (Exception ex)
            {
                MelonModLogger.LogError("Exception happened in GetReflectionData override; crash will likely follow: " + ex);
                return(IntPtr.Zero);
            }
        }
Ejemplo n.º 8
0
        public void EditMirrorLayersMenu(bool useBigMenu, VRC_MirrorReflection mirror)
        {
            ICustomShowableLayoutedMenu mirrorLayerMenu = null;

            mirrorLayerMenu = useBigMenu ? ExpansionKitApi.CreateCustomFullMenuPopup(LayoutDescriptionCustom.QuickMenu3Column) : ExpansionKitApi.CreateCustomQuickMenuPage(LayoutDescriptionCustom.QuickMenu3Column_Longer);

            if (mirror is null)
            {
                mirrorLayerMenu.AddLabel("Enable/Disable Layers on All Mirrors in a world");
            }
            else
            {
                mirrorLayerMenu.AddLabel("Enable/Disable Layers on specific mirror:");
            }
            if (mirror is null)
            {
                mirrorLayerMenu.AddSimpleButton($"All to Full", () => { SetSingleLayerOnMirrors(0, 10, mirror); });
            }
            else
            {
                mirrorLayerMenu.AddLabel($"{mirror.gameObject.name}");
            }
            if (mirror is null)
            {
                mirrorLayerMenu.AddSimpleButton($"All to Optimized", () => { SetSingleLayerOnMirrors(0, 11, mirror); });
            }
            else
            {
                mirrorLayerMenu.AddLabel($"{GetHierarchyPath(mirror.gameObject.transform)}");
            }

            mirrorLayerMenu.AddSimpleButton($"View Mirrors", () => { ViewMirrorLayers(useBigMenu); });
            if (mirror is null)
            {
                mirrorLayerMenu.AddSimpleButton($"Enable All", () => { SetSingleLayerOnMirrors(0, 5, mirror); });
            }
            else
            {
                mirrorLayerMenu.AddSimpleButton($"Enable All", () => { SetSingleLayerOnMirrors(0, 5, mirror); UpdateButtons(mirror.m_ReflectLayers); });
            }
            if (mirror is null)
            {
                mirrorLayerMenu.AddSimpleButton($"Disable All", () => { SetSingleLayerOnMirrors(0, 6, mirror); });
            }
            else
            {
                mirrorLayerMenu.AddSimpleButton($"Disable All", () => { SetSingleLayerOnMirrors(0, 6, mirror); UpdateButtons(mirror.m_ReflectLayers); });
            }

            foreach (KeyValuePair <int, string> entry in layerList)
            {
                if (mirror is null)
                {
                    mirrorLayerMenu.AddLabel($"Layer #{entry.Key} ----------- \n{entry.Value}");
                    mirrorLayerMenu.AddSimpleButton($"Enable", () => { SetSingleLayerOnMirrors(entry.Key, 1, mirror); });
                    mirrorLayerMenu.AddSimpleButton($"Disable", () => { SetSingleLayerOnMirrors(entry.Key, 0, mirror); });
                }
                else
                { //If editing solo mirror, show current state on lables
                    mirrorLayerMenu.AddLabel($"Layer #{entry.Key} {(IsLayerEnabled(mirror.m_ReflectLayers.value, entry.Key) ? "++++++++" : "-----------")} \n{entry.Value}", (button) => buttonList[entry.Key] = button.transform);
                    //mirrorLayerMenu.AddToggleButton($"Enable", b => {
                    //    if (b)
                    //        SetSingleLayerOnMirrors(entry.Key, 1, mirror);
                    //    else
                    //        SetSingleLayerOnMirrors(entry.Key, 0, mirror);

                    //}, () => IsLayerEnabled(mirror.m_ReflectLayers.value, entry.Key));

                    mirrorLayerMenu.AddSimpleButton($"Enable", () => { SetSingleLayerOnMirrors(entry.Key, 1, mirror); UpdateButtons(mirror.m_ReflectLayers.value); });
                    mirrorLayerMenu.AddSimpleButton($"Disable", () => { SetSingleLayerOnMirrors(entry.Key, 0, mirror); UpdateButtons(mirror.m_ReflectLayers.value); });
                }
            }

            mirrorLayerMenu.AddSimpleButton($"View Mirrors", () => { ViewMirrorLayers(useBigMenu); });
            mirrorLayerMenu.AddSimpleButton($"Close", () => { mirrorLayerMenu.Hide(); });
            if (mirror is null)
            {
                mirrorLayerMenu.AddSimpleButton($"Defaults Menu", () => { DefaultsMenu(useBigMenu); });
            }
            else
            {
                mirrorLayerMenu.AddSimpleButton($"Back", () => { EditMirrorLayersMenu(useBigMenu, null); });
            }


            mirrorLayerMenu.Show();
        }