Skip to content

Commit

Permalink
Move to live Enabled check in patches
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Jan 24, 2025
1 parent 2d63873 commit f9410f8
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 53 deletions.
5 changes: 3 additions & 2 deletions CommunityBugFixCollection/ColorDisplayValueProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ internal sealed class ColorDisplayValueProxy : ResoniteMonkey<ColorDisplayValueP

private static void Postfix(ValueDisplay<color> __instance, ProtoFluxNodeVisual visual)
{
if (!Enabled)
return;

var colorToColorX = visual.Slot.GetComponentInChildren<ColorToColorX>();
var textFormatDriver = visual.Slot.GetComponentInChildren<MultiValueTextFormatDriver>();

Expand All @@ -29,7 +32,5 @@ private static void Postfix(ValueDisplay<color> __instance, ProtoFluxNodeVisual
var valueProxySource = textFormatDriver.Slot.AttachComponent<ValueProxySource<color>>();
valueProxySource.Value.DriveFrom(__instance._value.Target);
}

private static bool Prepare() => Enabled;
}
}
7 changes: 5 additions & 2 deletions CommunityBugFixCollection/ColorXNodeNamesSpacing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ internal sealed class ColorXNodeNamesSpacing : ResoniteMonkey<ColorXNodeNamesSpa
public override bool CanBeDisabled => true;

private static string Postfix(string __result)
=> __result.Replace("Color X", "ColorX ");
{
if (!Enabled)
return __result;

private static bool Prepare() => Enabled;
return __result.Replace("Color X", "ColorX ");
}
}
}
7 changes: 5 additions & 2 deletions CommunityBugFixCollection/CorrectMaterialGizmoScaling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ internal sealed class CorrectMaterialGizmoScaling : ResoniteMonkey<CorrectMateri

// Apply default scale for inspector UI before it gets user-scaled again by PositionInFrontOfUser
private static void Prefix(MaterialGizmo __instance)
=> __instance._inspectorRoot.Target.LocalScale = 0.0005f * float3.One;
{
if (!Enabled)
return;

private static bool Prepare() => Enabled;
__instance._inspectorRoot.Target.LocalScale = 0.0005f * float3.One;
}
}
}
27 changes: 22 additions & 5 deletions CommunityBugFixCollection/FireBrushToolDequipEvents.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FrooxEngine;
using HarmonyLib;
using MonkeyLoader.Patching;
using MonkeyLoader.Resonite;
using System;
using System.Collections.Generic;
Expand All @@ -9,23 +10,39 @@
namespace CommunityBugFixCollection
{
[HarmonyPatchCategory(nameof(FireBrushToolDequipEvents))]
[HarmonyPatch(typeof(BrushTool), nameof(BrushTool.OnDequipped))]
[HarmonyPatch(nameof(BrushTool.OnDequipped))]
internal sealed class FireBrushToolDequipEvents : ResoniteMonkey<FireBrushToolDequipEvents>
{
public override IEnumerable<string> Authors => Contributors.Banane9;

public override bool CanBeDisabled => true;

private static bool Prepare() => Enabled;

private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
[HarmonyTranspiler]
[HarmonyPatch(typeof(BrushTool))]
private static IEnumerable<CodeInstruction> BrushToolOnDequippedTranspiler(IEnumerable<CodeInstruction> instructions)
{
return new[]
{
CodeInstruction.LoadArgument(0),
CodeInstruction.Call((Tool tool) => tool.OnDequipped())
CodeInstruction.Call((Tool tool) => ToolOnDequippedProxy(tool))
}
.Concat(instructions);
}

[HarmonyReversePatch]
[HarmonyPatch(typeof(Tool))]
private static void ToolOnDequipped(Tool tool)
=> throw new NotImplementedException("Harmony Reverse Patch!");

/// <summary>
/// Proxy to be able to control the fix through <see cref="MonkeyBase{T}.Enabled"/>.
/// </summary>
private static void ToolOnDequippedProxy(Tool tool)
{
if (!Enabled)
return;

ToolOnDequipped(tool);
}
}
}
7 changes: 4 additions & 3 deletions CommunityBugFixCollection/GammaCorrectedColorXLuminance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ internal sealed class GammaCorrectedColorXLuminance : ResoniteMonkey<GammaCorrec

public override bool CanBeDisabled => true;

private static bool Prefix(colorX __instance, out float __result)
private static bool Prefix(colorX __instance, ref float __result)
{
if (!Enabled)
return true;

__result = __instance.ConvertProfile(ColorProfile.Linear).BaseColor.Luminance;

return false;
}

private static bool Prepare() => Enabled;
}
}
5 changes: 2 additions & 3 deletions CommunityBugFixCollection/HighlightHomeWorldInInventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ internal sealed class HighlightHomeWorldInInventory : ResoniteMonkey<HighlightHo

private static void Postfix(InventoryBrowser __instance, InventoryItemUI item)
{
if (InventoryBrowser.ClassifyItem(item) != InventoryBrowser.SpecialItemType.World
if (!Enabled
|| InventoryBrowser.ClassifyItem(item) != InventoryBrowser.SpecialItemType.World
|| __instance.GetItemWorldUri(item) != __instance.Engine.Cloud.Profile.GetCurrentFavorite(FavoriteEntity.Home))
return;

item.NormalColor.Value = InventoryBrowser.FAVORITE_COLOR;
item.SelectedColor.Value = InventoryBrowser.FAVORITE_COLOR.MulRGB(2f);
}

private static bool Prepare() => Enabled;
}
}
4 changes: 1 addition & 3 deletions CommunityBugFixCollection/ImportMultipleAudioFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,11 @@ private static async Task ImportAudioAsync(IEnumerable<string> files, World worl

private static bool Prefix(ref Task? __result, AssetClass assetClass, IEnumerable<string> files, World world, float3 position, floatQ rotation, float3 scale)
{
if (assetClass != AssetClass.Audio)
if (!Enabled || assetClass != AssetClass.Audio)
return true;

__result = ImportAudioAsync(files, world, position, rotation, scale);
return false;
}

private static bool Prepare() => Enabled;
}
}
7 changes: 4 additions & 3 deletions CommunityBugFixCollection/ImportWebFilesAsUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ internal sealed class ImportWebFilesAsUrls : ResoniteMonkey<ImportWebFilesAsUrls

public override bool CanBeDisabled => true;

private static bool Prefix(out AssetClass __result, string path)
private static bool Prefix(ref AssetClass __result, string path)
{
if (!Enabled)
return true;

if (path is null)
{
__result = AssetClass.Unknown;
Expand Down Expand Up @@ -75,7 +78,5 @@ private static bool Prefix(out AssetClass __result, string path)
__result = AssetClass.Unknown;
return false;
}

private static bool Prepare() => Enabled;
}
}
22 changes: 17 additions & 5 deletions CommunityBugFixCollection/NoLossOfColorProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,27 @@ private static colorX NormalizeHDRPostfix(colorX __result, colorX __instance)
private static class ColorXBlendingPatches
{
private static colorX Postfix(colorX __result, ColorProfile __state)
=> new(__result.BaseColor, __state);
{
if (!Enabled)
return __result;

return new(__result.BaseColor, __state);
}

private static void Prefix(ref colorX src, ref colorX dst, out ColorProfile __state)
{
if (!Enabled)
{
__state = default;
return;
}

var operands = ColorProfileHelper.GetOperands(in src, in dst, ColorProfileAwareOperation.LinearIfUnequal);
src = new(operands.leftHand, operands.profile);
dst = new(operands.rightHand, operands.profile);
__state = operands.profile;
}

private static bool Prepare() => Enabled;

private static IEnumerable<MethodBase> TargetMethods()
{
var methodNames = new[]
Expand All @@ -67,9 +76,12 @@ private static IEnumerable<MethodBase> TargetMethods()
private static class ColorXChannelAddingPatches
{
private static colorX Postfix(colorX __result, colorX __instance)
=> new(__result.BaseColor, __instance.Profile);
{
if (!Enabled)
return __result;

private static bool Prepare() => Enabled;
return new(__result.BaseColor, __instance.Profile);
}

private static IEnumerable<MethodBase> TargetMethods()
{
Expand Down
4 changes: 1 addition & 3 deletions CommunityBugFixCollection/NoZeroScaleToolRaycast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ internal sealed class NoZeroScaleToolRaycast : ResoniteMonkey<NoZeroScaleToolRay

[HarmonyPrefix]
private static bool GetHitPrefix(Tool __instance)
=> __instance.TipForward.IsValid() && __instance.TipForward != float3.Zero;

private static bool Prepare() => Enabled;
=> !Enabled || (__instance.TipForward.IsValid() && __instance.TipForward != float3.Zero);
}
}
69 changes: 55 additions & 14 deletions CommunityBugFixCollection/NodeNameAdjustments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using System.Collections.Generic;
using System.Text;

#pragma warning disable IDE0060 // Remove unused parameter

namespace CommunityBugFixCollection
{
[HarmonyPatchCategory(nameof(NodeNameAdjustments))]
Expand All @@ -22,50 +20,93 @@ internal sealed class NodeNameAdjustments : ResoniteMonkey<NodeNameAdjustments>
[HarmonyPostfix]
[HarmonyPatch(typeof(Backspace))]
private static string BackspaceNamePostfix(string __result)
=> "Backspace (\\b)";
{
if (!Enabled)
return __result;

return "Backspace (\\b)";
}

[HarmonyPostfix]
[HarmonyPatch(typeof(Bell))]
private static string BellNamePostfix(string __result)
=> "Bell (\\a)";
{
if (!Enabled)
return __result;

return "Bell (\\a)";
}

[HarmonyPostfix]
[HarmonyPatch(typeof(CarriageReturn))]
private static string CarriageReturnNamePostfix(string __result)
=> "Carriage Return (\\r)";
{
if (!Enabled)
return __result;

return "Carriage Return (\\r)";
}

[HarmonyPostfix]
[HarmonyPatch(typeof(FormFeed))]
private static string FormFeedNamePostfix(string __result)
=> "Form Feed (\\f)";
{
if (!Enabled)
return __result;

return "Form Feed (\\f)";
}

private static bool Prepare() => Enabled;

[HarmonyPostfix]
[HarmonyPatch(typeof(Remap11_01_Double))]
private static string Remap11_01_DoubleNamePostfix(string __result)
=> "Remap [-1; 1] to [0; 1]";
{
if (!Enabled)
return __result;

return "Remap [-1; 1] to [0; 1]";
}

[HarmonyPostfix]
[HarmonyPatch(typeof(Remap11_01_Float))]
private static string Remap11_01_FloatNamePostfix(string __result)
=> "Remap [-1; 1] to [0; 1]";
{
if (!Enabled)
return __result;

return "Remap [-1; 1] to [0; 1]";
}

[HarmonyPostfix]
[HarmonyPatch(typeof(Space))]
private static string SpaceNamePostfix(string __result)
=> "Space ( )";
{
if (!Enabled)
return __result;

return "Space ( )";
}

[HarmonyPostfix]
[HarmonyPatch(typeof(Tab))]
private static string TabNamePostfix(string __result)
=> "Tab (\\t)";
{
if (!Enabled)
return __result;

return "Tab (\\t)";
}

[HarmonyPostfix]
[HarmonyPatch(typeof(VerticalTab))]
private static string VerticalTabNamePostfix(string __result)
=> "Vertical Tab (\\v)";
}
}
{
if (!Enabled)
return __result;

#pragma warning restore IDE0060 // Remove unused parameter
return "Vertical Tab (\\v)";
}
}
}
14 changes: 10 additions & 4 deletions CommunityBugFixCollection/NonHDRColorClamping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ internal sealed class NonHDRColorClamping : ResoniteMonkey<NonHDRColorClamping>
private static class ColorPatches
{
private static color Postfix(color __result)
=> new(MathX.Clamp01(__result.rgba));
{
if (!Enabled)
return __result;

private static bool Prepare() => Enabled;
return new(MathX.Clamp01(__result.rgba));
}

private static IEnumerable<MethodBase> TargetMethods()
{
Expand All @@ -42,9 +45,12 @@ private static IEnumerable<MethodBase> TargetMethods()
private static class ColorXPatches
{
private static colorX Postfix(colorX __result)
=> MathX.Clamp01(in __result);
{
if (!Enabled)
return __result;

private static bool Prepare() => Enabled;
return MathX.Clamp01(in __result);
}

private static IEnumerable<MethodBase> TargetMethods()
{
Expand Down
Loading

0 comments on commit f9410f8

Please sign in to comment.