diff --git a/MiraAPI/Colors/ColorSpaces/CmykColor.cs b/MiraAPI/Colors/ColorSpaces/CmykColor.cs
index 268dc81..c94ebec 100644
--- a/MiraAPI/Colors/ColorSpaces/CmykColor.cs
+++ b/MiraAPI/Colors/ColorSpaces/CmykColor.cs
@@ -21,7 +21,7 @@ public record struct CmykColor(float c, float m, float y, float k, float a = 1f)
/// Implicitly converts a to a Unity .
///
/// The color being converted.
- public static implicit operator Color(in CmykColor c)
+ public static implicit operator Color(CmykColor c)
{
return ToColor(c);
}
@@ -30,7 +30,7 @@ public record struct CmykColor(float c, float m, float y, float k, float a = 1f)
/// Implicitly converts a Unity to a .
///
/// The color being converted.
- public static implicit operator CmykColor(in Color c)
+ public static implicit operator CmykColor(Color c)
{
return FromColor(c);
}
@@ -40,7 +40,7 @@ public record struct CmykColor(float c, float m, float y, float k, float a = 1f)
///
/// The CMYK color to convert.
/// A Unity representing the same visual color.
- public static Color ToColor(in CmykColor cmyk)
+ public static Color ToColor(CmykColor cmyk)
{
var r = (1f - cmyk.c) * (1f - cmyk.k);
var g = (1f - cmyk.m) * (1f - cmyk.k);
@@ -54,7 +54,7 @@ public record struct CmykColor(float c, float m, float y, float k, float a = 1f)
///
/// The Unity Color to convert.
/// A representing the same visual color.
- public static CmykColor FromColor(in Color color)
+ public static CmykColor FromColor(Color color)
{
var r = color.r;
var g = color.g;
@@ -81,7 +81,7 @@ public record struct CmykColor(float c, float m, float y, float k, float a = 1f)
/// The ending color.
/// The interpolation value between the two colors, clamped to a 0 to 1 range.
/// The interpolated .
- public static CmykColor Lerp(in CmykColor a, in CmykColor b, float t)
+ public static CmykColor Lerp(CmykColor a, CmykColor b, float t)
{
return LerpUnclamped(a, b, MathUtilities.Clamp01(t));
}
@@ -93,7 +93,7 @@ public record struct CmykColor(float c, float m, float y, float k, float a = 1f)
/// The ending color.
/// The interpolation value between the two colors.
/// The interpolated .
- public static CmykColor LerpUnclamped(in CmykColor a, in CmykColor b, float t)
+ public static CmykColor LerpUnclamped(CmykColor a, CmykColor b, float t)
{
return new CmykColor(
MathUtilities.LerpUnclamped(a.c, b.c, t),
diff --git a/MiraAPI/Colors/ColorSpaces/HsbColor.cs b/MiraAPI/Colors/ColorSpaces/HsbColor.cs
index 160ae85..b566333 100644
--- a/MiraAPI/Colors/ColorSpaces/HsbColor.cs
+++ b/MiraAPI/Colors/ColorSpaces/HsbColor.cs
@@ -20,7 +20,7 @@ public record struct HsbColor(float h, float s, float b, float a = 1f)
/// Implicitly converts an to a Unity .
///
/// The color being converted.
- public static implicit operator Color(in HsbColor c)
+ public static implicit operator Color(HsbColor c)
{
return ToColor(c);
}
@@ -29,7 +29,7 @@ public record struct HsbColor(float h, float s, float b, float a = 1f)
/// Implicitly converts a Unity to an .
///
/// The color being converted.
- public static implicit operator HsbColor(in Color c)
+ public static implicit operator HsbColor(Color c)
{
return FromColor(c);
}
@@ -39,7 +39,7 @@ public record struct HsbColor(float h, float s, float b, float a = 1f)
///
/// The HSB color to convert.
/// A Unity representing the same visual color.
- public static Color ToColor(in HsbColor hsb)
+ public static Color ToColor(HsbColor hsb)
{
if (hsb.s <= float.Epsilon)
return new Color(MathUtilities.Clamp01(hsb.b), MathUtilities.Clamp01(hsb.b), MathUtilities.Clamp01(hsb.b), hsb.a);
@@ -72,7 +72,7 @@ public record struct HsbColor(float h, float s, float b, float a = 1f)
///
/// The Unity Color to convert.
/// An representing the same visual color.
- public static HsbColor FromColor(in Color color)
+ public static HsbColor FromColor(Color color)
{
var max = MathF.Max(color.r, MathF.Max(color.g, color.b));
var min = MathF.Min(color.r, MathF.Min(color.g, color.b));
@@ -108,7 +108,7 @@ public record struct HsbColor(float h, float s, float b, float a = 1f)
/// The ending color.
/// The interpolation value between the two colors, clamped to a 0 to 1 range.
/// The interpolated .
- public static HsbColor Lerp(in HsbColor a, in HsbColor b, float t)
+ public static HsbColor Lerp(HsbColor a, HsbColor b, float t)
{
return LerpUnclamped(a, b, MathUtilities.Clamp01(t));
}
@@ -120,7 +120,7 @@ public record struct HsbColor(float h, float s, float b, float a = 1f)
/// The ending color.
/// The interpolation value between the two colors.
/// The interpolated .
- public static HsbColor LerpUnclamped(in HsbColor a, in HsbColor b, float t)
+ public static HsbColor LerpUnclamped(HsbColor a, HsbColor b, float t)
{
var hueDifference = MathUtilities.Repeat(b.h - a.h, 1f);
diff --git a/MiraAPI/Colors/ColorSpaces/HslColor.cs b/MiraAPI/Colors/ColorSpaces/HslColor.cs
index 5ff7077..1929e77 100644
--- a/MiraAPI/Colors/ColorSpaces/HslColor.cs
+++ b/MiraAPI/Colors/ColorSpaces/HslColor.cs
@@ -20,7 +20,7 @@ public record struct HslColor(float h, float s, float l, float a = 1f)
/// Implicitly converts an to a Unity .
///
/// The color being converted.
- public static implicit operator Color(in HslColor c)
+ public static implicit operator Color(HslColor c)
{
return ToColor(c);
}
@@ -29,7 +29,7 @@ public record struct HslColor(float h, float s, float l, float a = 1f)
/// Implicitly converts a Unity to an .
///
/// The color being converted.
- public static implicit operator HslColor(in Color c)
+ public static implicit operator HslColor(Color c)
{
return FromColor(c);
}
@@ -39,7 +39,7 @@ public record struct HslColor(float h, float s, float l, float a = 1f)
///
/// The HSL color to convert.
/// A Unity representing the same visual color.
- public static Color ToColor(in HslColor hsl)
+ public static Color ToColor(HslColor hsl)
{
if (hsl.s <= float.Epsilon)
return new Color(MathUtilities.Clamp01(hsl.l), MathUtilities.Clamp01(hsl.l), MathUtilities.Clamp01(hsl.l), hsl.a);
@@ -68,7 +68,7 @@ public record struct HslColor(float h, float s, float l, float a = 1f)
///
/// The Unity Color to convert.
/// An representing the same visual color.
- public static HslColor FromColor(in Color color)
+ public static HslColor FromColor(Color color)
{
var max = MathF.Max(color.r, MathF.Max(color.g, color.b));
var min = MathF.Min(color.r, MathF.Min(color.g, color.b));
@@ -104,7 +104,7 @@ public record struct HslColor(float h, float s, float l, float a = 1f)
/// The ending color.
/// The interpolation value between the two colors, clamped to a 0 to 1 range.
/// The interpolated .
- public static HslColor Lerp(in HslColor a, in HslColor b, float t)
+ public static HslColor Lerp(HslColor a, HslColor b, float t)
{
return LerpUnclamped(a, b, MathUtilities.Clamp01(t));
}
@@ -116,7 +116,7 @@ public record struct HslColor(float h, float s, float l, float a = 1f)
/// The ending color.
/// The interpolation value between the two colors.
/// The interpolated .
- public static HslColor LerpUnclamped(in HslColor a, in HslColor b, float t)
+ public static HslColor LerpUnclamped(HslColor a, HslColor b, float t)
{
var hueDifference = MathUtilities.Repeat(b.h - a.h, 1f);
diff --git a/MiraAPI/Colors/PaletteManager.cs b/MiraAPI/Colors/PaletteManager.cs
index b552521..5fc961a 100644
--- a/MiraAPI/Colors/PaletteManager.cs
+++ b/MiraAPI/Colors/PaletteManager.cs
@@ -34,7 +34,7 @@ public static class PaletteManager
Palette.TextColors = Palette.TextColors.ToArray().AddRangeToArray(colors);
Palette.TextOutlineColors = Palette.TextOutlineColors.ToArray().AddRangeToArray(shadowColors);
- for (var i = 0; i < originalLength + CustomColors.Count; i++)
+ for (var i = 0; i < CustomColors.Count; i++)
ColorIdToColorMap[i + originalLength] = CustomColors[i];
}
@@ -68,7 +68,7 @@ public static class PaletteManager
return !ColorIdToColorMap.TryGetValue(colorId, out var custom)
? Palette.PlayerColors[colorId]
: (custom is VariableColor variable
- ? variable.EvaluateMainColor()
+ ? variable.EvaluateMainColor(Time.time)
: custom.InternalMainColor);
}
@@ -82,7 +82,7 @@ public static class PaletteManager
return !ColorIdToColorMap.TryGetValue(colorId, out var custom)
? Palette.ShadowColors[colorId]
: (custom is VariableColor variable
- ? variable.EvaluateShadowColor()
+ ? variable.EvaluateShadowColor(Time.time)
: custom.InternalShadowColor);
}
}
diff --git a/MiraAPI/Colors/VariableColor.cs b/MiraAPI/Colors/VariableColor.cs
index 2655ff5..93f736d 100644
--- a/MiraAPI/Colors/VariableColor.cs
+++ b/MiraAPI/Colors/VariableColor.cs
@@ -48,22 +48,24 @@ public sealed class VariableColor(StringNames name, Func mainEvalu
///
/// Evaluates the dynamic main color based on the current in-game time.
///
+ /// The time to evaluate the color against.
/// The dynamically evaluated color, or the static if static variant colors are enabled in the user's settings.
- public Color EvaluateMainColor()
+ public Color EvaluateMainColor(float time)
{
return LocalSettingsTabSingleton.Instance.EnableVariableColors.Value
- ? MainEvaluator(Time.time)
+ ? MainEvaluator(time)
: InternalMainColor;
}
///
/// Evaluates the dynamic shadow color based on the current in-game time.
///
+ /// The time to evaluate the color against.
/// The dynamically evaluated color, or the static if static variant colors are enabled in the user's settings.
- public Color EvaluateShadowColor()
+ public Color EvaluateShadowColor(float time)
{
return LocalSettingsTabSingleton.Instance.EnableVariableColors.Value
- ? ShadowEvaluator(Time.time)
+ ? ShadowEvaluator(time)
: InternalShadowColor;
}
}
diff --git a/MiraAPI/Colors/VariableColorBehaviour.cs b/MiraAPI/Colors/VariableColorBehaviour.cs
index f33a12c..2d6b6d0 100644
--- a/MiraAPI/Colors/VariableColorBehaviour.cs
+++ b/MiraAPI/Colors/VariableColorBehaviour.cs
@@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis;
using Il2CppInterop.Runtime.Attributes;
using MiraAPI.Colors;
using MiraAPI.Utilities;
+using Reactor.Utilities.Attributes;
using UnityEngine;
namespace MiraAPI;
@@ -9,6 +10,7 @@ namespace MiraAPI;
///
/// A mono script that adjusts the material colors of a component that it's attached to based on the provided variable color.
///
+[RegisterInIl2Cpp]
[SuppressMessage("Style", "IDE0051:Remove unused private members", Justification = "Unity methods.")]
[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Unity fields.")]
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")]
@@ -34,6 +36,7 @@ public sealed class VariableColorBehaviour : MonoBehaviour
{
rend = GetComponent();
material = rend.material;
+ material.SetColor(ShaderID.VisorColor, VisorColor);
}
private void Update()
@@ -41,8 +44,8 @@ public sealed class VariableColorBehaviour : MonoBehaviour
if (!rend || color == null)
return;
- material.SetColor(ShaderID.BodyColor, color.EvaluateMainColor());
- material.SetColor(ShaderID.BackColor, color.EvaluateShadowColor());
- material.SetColor(ShaderID.VisorColor, VisorColor);
+ var time = Time.time;
+ material.SetColor(ShaderID.BodyColor, color.EvaluateMainColor(time));
+ material.SetColor(ShaderID.BackColor, color.EvaluateShadowColor(time));
}
}
diff --git a/MiraAPI/Hud/CustomPaginableMenu.cs b/MiraAPI/Hud/CustomPaginableMenu.cs
index 27f7819..c000fd8 100644
--- a/MiraAPI/Hud/CustomPaginableMenu.cs
+++ b/MiraAPI/Hud/CustomPaginableMenu.cs
@@ -5,6 +5,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
using MiraAPI.Patches.Stubs;
using MiraAPI.Translation;
+using MiraAPI.Utilities;
using MiraAPI.Utilities.Assets;
using Reactor.Utilities;
using Reactor.Utilities.Extensions;
@@ -248,8 +249,7 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu()
- ?? searchTextbox.gameObject.AddComponent();
+ var searchFocusButton = searchTextbox.gameObject.GetOrAddComponent();
if (wikiClickSound != null)
{
searchFocusButton.ClickSound = wikiClickSound;
diff --git a/MiraAPI/Patches/Hud/VariableColorPatches.cs b/MiraAPI/Patches/Hud/VariableColorPatches.cs
index 628a1f4..3b52b7b 100644
--- a/MiraAPI/Patches/Hud/VariableColorPatches.cs
+++ b/MiraAPI/Patches/Hud/VariableColorPatches.cs
@@ -3,6 +3,8 @@ using System.Text.RegularExpressions;
using AmongUs.Data;
using HarmonyLib;
using MiraAPI.Colors;
+using MiraAPI.Utilities;
+using Reactor.Utilities.Extensions;
using UnityEngine;
namespace MiraAPI.Patches.Hud;
@@ -13,18 +15,17 @@ internal static class SetPlayerMaterialPatch
[HarmonyPatch(nameof(PlayerMaterial.SetColors), typeof(int), typeof(Renderer))]
public static bool Prefix(int colorId, Renderer rend)
{
- var r = rend.gameObject.GetComponent()
- ?? rend.gameObject.AddComponent();
- r.SetColor(PaletteManager.IsVariable(colorId) ? (VariableColor)PaletteManager.ColorIdToColorMap[colorId] : null);
+ rend.gameObject.GetOrAddComponent().SetColor(
+ PaletteManager.ColorIdToColorMap.TryGetValue(colorId, out var color) && color is VariableColor variable
+ ? variable
+ : null);
return !PaletteManager.IsVariable(colorId);
}
[HarmonyPatch(nameof(PlayerMaterial.SetColors), typeof(Color), typeof(Renderer))]
public static void Prefix(Renderer rend)
{
- var r = rend.gameObject.GetComponent()
- ?? rend.gameObject.AddComponent();
- r.SetColor(null);
+ rend.gameObject.GetOrAddComponent().SetColor(null);
}
}
@@ -48,7 +49,7 @@ internal static class ChatNotifRainbowPatch
if (!__instance.gameObject.active || !PaletteManager.IsVariable(__instance.player.cosmetics.ColorId))
return;
- var str = ColorUtility.ToHtmlStringRGB(PaletteManager.GetMainColor(__instance.player.cosmetics.ColorId));
+ var str = PaletteManager.GetMainColor(__instance.player.cosmetics.ColorId).ToHtmlStringRGBA();
__instance.playerNameText.text = "" + __instance.playerNameText.text.WithoutRichText();
}
@@ -71,9 +72,9 @@ internal static class RainbowLobbyInfoPanePatch
}
var host = GameData.Instance.GetHost();
- var text = ColorUtility.ToHtmlStringRGB(PaletteManager.GetMainColor(__instance.player.cosmetics.ColorId));
- __instance.hostLabel.text =
- TranslationController.Instance.GetString(StringNames.HostNounLabel);
+ var text = PaletteManager.GetMainColor(__instance.player.cosmetics.ColorId).ToHtmlStringRGBA();
+ __instance.hostLabel.text = TranslationController.Instance.GetString(StringNames.HostNounLabel);
+
if (__instance.ShouldBoldenHostLabel(DataManager.Settings.Language.CurrentLanguage))
{
__instance.hostLabel.text = __instance.hostLabel.text.Insert(0, "");
diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs
index 9058eac..b46d155 100644
--- a/MiraAPI/PluginLoading/MiraPluginManager.cs
+++ b/MiraAPI/PluginLoading/MiraPluginManager.cs
@@ -404,7 +404,7 @@ public sealed class MiraPluginManager
foreach (var property in type.GetProperties())
{
- if (property.PropertyType.IsAssignableTo(typeof(CustomColor)))
+ if (!property.PropertyType.IsAssignableTo(typeof(CustomColor)))
{
continue;
}
diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs
index 9017d13..c3874e1 100644
--- a/MiraAPI/Utilities/Extensions.cs
+++ b/MiraAPI/Utilities/Extensions.cs
@@ -871,4 +871,17 @@ public static class Extensions
userData.joystickMaps[0].actionElementMaps.Add(map);
return action;
}
+
+ ///
+ /// Gets a component that is attached to the provided , attaching and returning the component if it wasn't found.
+ ///
+ /// The component type.
+ /// The to get the component from.
+ /// The component.
+ public static T GetOrAddComponent(this GameObject go)
+ where T : Component
+ {
+ var comp = go.GetComponent();
+ return comp ? comp : go.AddComponent();
+ }
}