Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions CommunityBugFixCollection/NonHDRColorClamping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Elements.Core;
using HarmonyLib;
using MonkeyLoader.Resonite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace CommunityBugFixCollection
{
internal sealed class NonHDRColorClamping : ResoniteMonkey<NonHDRColorClamping>
{
public override bool CanBeDisabled => true;

[HarmonyPatch]
[HarmonyPatchCategory(nameof(NonHDRColorClamping))]
private static class ColorXPatches
{
private static bool Prepare() => Enabled;

private static IEnumerable<MethodBase> TargetMethods()
{
var methodNames = new[]
{
nameof(colorX.AddR), nameof(colorX.AddG), nameof(colorX.AddB), nameof(colorX.AddA)
};

return methodNames
.Select(name => AccessTools.DeclaredMethod(typeof(colorX), name))
.Where(method => method is not null);
}

private static colorX Postfix(colorX __result)
=> MathX.Clamp01(in __result);
}

[HarmonyPatch]
[HarmonyPatchCategory(nameof(NonHDRColorClamping))]
private static class ColorPatches
{
private static bool Prepare() => Enabled;

private static IEnumerable<MethodBase> TargetMethods()
{
var methodNames = new[]
{
nameof(color.AddR), nameof(color.AddG), nameof(color.AddB), nameof(color.AddA)
};

return methodNames
.Select(name => AccessTools.DeclaredMethod(typeof(color), name))
.Where(method => method is not null);
}

private static color Postfix(color __result)
=> new(MathX.Clamp01(__result.rgba));
}
}
}
Loading