Exemplo n.º 1
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);
            }
        }