Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Dec 13, 2024
1 parent c3fd74b commit b525f47
Showing 1 changed file with 60 additions and 0 deletions.
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));
}
}
}

0 comments on commit b525f47

Please sign in to comment.