static bool Prefix(ColorCorrectionCurves __instance) { __instance.CheckResources(); var rgbChannelTex = Traverse.Create(__instance).Field("rgbChannelTex"); if (CCCCustom == 0 && __instance.redChannel != null && __instance.greenChannel != null && __instance.blueChannel != null) { for (float num = 0f; num <= 1f; num += 0.0009775171f) { float num2 = Mathf.Clamp(__instance.redChannel.Evaluate(num), 0f, 1f); float num3 = Mathf.Clamp(__instance.greenChannel.Evaluate(num), 0f, 1f); float num4 = Mathf.Clamp(__instance.blueChannel.Evaluate(num), 0f, 1f); rgbChannelTex.Method("SetPixel", new Type[] { typeof(int), typeof(int), typeof(Color) }).GetValue((int)Mathf.Ceil(num * 1023f), 0, new Color(num2, num2, num2)); rgbChannelTex.Method("SetPixel", new Type[] { typeof(int), typeof(int), typeof(Color) }).GetValue((int)Mathf.Ceil(num * 1023f), 1, new Color(num3, num3, num3)); rgbChannelTex.Method("SetPixel", new Type[] { typeof(int), typeof(int), typeof(Color) }).GetValue((int)Mathf.Ceil(num * 1023f), 2, new Color(num4, num4, num4)); } rgbChannelTex.Method("Apply", new Type[] { typeof(bool) }).GetValue(false); return(false); } string text = Path.Combine(Application.dataPath, "../UserData/curve/" + CCCName + ".dds"); Debug.Log("Using custom curve " + text); byte[] array = File.ReadAllBytes(text); int num5 = 128; byte[] array2 = new byte[array.Length - num5]; Buffer.BlockCopy(array, num5, array2, 0, array2.Length - num5); rgbChannelTex.Method("LoadRawTextureData", new Type[] { typeof(byte[]) }).GetValue(array2); rgbChannelTex.Method("Apply", new Type[] { typeof(bool) }).GetValue(false); return(false); }
static bool Prefix(ref RenderTexture source, ref RenderTexture destination, ColorCorrectionCurves __instance) { if (!__instance.CheckResources()) { Graphics.Blit(source, destination); return(false); } var traverse = Traverse.Create(__instance); var updateTexturesOnStartup = traverse.Field("updateTexturesOnStartup"); if (traverse.Field("updateTexturesOnStartup").GetValue <bool>()) { __instance.UpdateParameters(); traverse.Field("updateTexturesOnStartup").SetValue(false); } RenderTexture renderTexture = destination; if (__instance.selectiveCc) { renderTexture = RenderTexture.GetTemporary(source.width, source.height, 0, RenderTextureFormat.DefaultHDR); } traverse.Field("ccMaterial").Method("SetTexture", new Type[] { typeof(string), typeof(Texture2D) }).GetValue("_RgbTex", traverse.Field("rgbChannelTex").GetValue()); traverse.Field("ccMaterial").Method("SetFloat", new Type[] { typeof(string), typeof(float) }).GetValue("_Saturation", __instance.saturation); Graphics.Blit(source, renderTexture, traverse.Field("ccMaterial").GetValue <Material>()); if (__instance.selectiveCc) { var SetColor = traverse.Field("selectiveCcMaterial").Method("SetColor", new Type[] { typeof(string), typeof(Color) }); SetColor.GetValue("selColor", __instance.selectiveFromColor); SetColor.GetValue("targetColor", __instance.selectiveToColor); Graphics.Blit(renderTexture, destination, traverse.Field("selectiveCcMaterial").GetValue <Material>()); RenderTexture.ReleaseTemporary(renderTexture); } return(false); }