using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RepoRainbowMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RepoRainbowMod")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0b98ca04-e542-4311-9acf-59a0223de59c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ColorCycleMod;
[BepInPlugin("Maflingus.ColorCycler", "ColorCycler", "1.2.2")]
public class ColorCycleModBase : BaseUnityPlugin
{
public enum ColorEffectMode
{
Rainbow,
PoliceSiren,
Strobe,
Matrix,
Sunset,
Ocean,
Random,
Camouflage
}
public class ColorEffector : MonoBehaviour
{
private float timer = 0f;
private int currentColorIndex = 0;
private PlayerAvatar playerAvatar;
private List<Color> availableColors;
private bool initialized = false;
private int policeIndex = 0;
private int lastRandomIndex = -1;
private List<int> matrixIndices = new List<int>();
private List<int> sunsetIndices = new List<int>();
private List<int> oceanIndices = new List<int>();
private List<int> camoIndices = new List<int>();
private void Start()
{
playerAvatar = ((Component)this).GetComponent<PlayerAvatar>();
if ((Object)(object)playerAvatar == (Object)null)
{
Object.Destroy((Object)(object)this);
}
else
{
((MonoBehaviour)this).StartCoroutine(WaitForAssetManager());
}
}
private IEnumerator WaitForAssetManager()
{
yield return (object)new WaitForSeconds(2f);
int attempts = 0;
while (((Object)(object)AssetManager.instance == (Object)null || AssetManager.instance.playerColors == null) && attempts < 10)
{
Instance.mls.LogInfo((object)"Waiting for AssetManager...");
yield return (object)new WaitForSeconds(1f);
attempts++;
}
if ((Object)(object)AssetManager.instance == (Object)null || AssetManager.instance.playerColors == null)
{
Instance.mls.LogError((object)"Failed to find AssetManager.instance.playerColors after multiple attempts");
Object.Destroy((Object)(object)this);
yield break;
}
availableColors = AssetManager.instance.playerColors;
currentColorIndex = Random.Range(0, availableColors.Count);
InitializeSpecialModeColors();
ApplyColorEffect();
initialized = true;
}
private void InitializeSpecialModeColors()
{
FindColorIndices();
}
private void FindColorIndices()
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_021f: Unknown result type (might be due to invalid IL or missing references)
//IL_0245: Unknown result type (might be due to invalid IL or missing references)
//IL_026b: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
matrixIndices.Clear();
sunsetIndices.Clear();
oceanIndices.Clear();
camoIndices.Clear();
for (int i = 0; i < availableColors.Count; i++)
{
Color val = availableColors[i];
if (val.g > val.r * 1.5f && val.g > val.b * 1.5f)
{
matrixIndices.Add(i);
}
if (val.r > 0.6f && val.r > val.b * 1.5f)
{
sunsetIndices.Add(i);
}
if (val.b > 0.6f && val.b > val.r * 1.2f)
{
oceanIndices.Add(i);
}
if ((val.g > val.r && val.g > val.b) || (val.r > 0.4f && val.g > 0.4f && val.b < 0.3f))
{
camoIndices.Add(i);
}
}
if (matrixIndices.Count == 0)
{
matrixIndices.Add(GetClosestColorIndex(Color.green));
}
if (sunsetIndices.Count == 0)
{
sunsetIndices.Add(GetClosestColorIndex(Color.red));
sunsetIndices.Add(GetClosestColorIndex(new Color(1f, 0.5f, 0f)));
sunsetIndices.Add(GetClosestColorIndex(Color.yellow));
}
if (oceanIndices.Count == 0)
{
oceanIndices.Add(GetClosestColorIndex(Color.blue));
oceanIndices.Add(GetClosestColorIndex(new Color(0f, 0.5f, 1f)));
oceanIndices.Add(GetClosestColorIndex(new Color(0.5f, 0f, 0.5f)));
}
if (camoIndices.Count == 0)
{
camoIndices.Add(GetClosestColorIndex(new Color(0.4f, 0.3f, 0.2f)));
camoIndices.Add(GetClosestColorIndex(new Color(0.2f, 0.4f, 0.1f)));
camoIndices.Add(GetClosestColorIndex(new Color(0.7f, 0.7f, 0.5f)));
}
}
private int GetClosestColorIndex(Color targetColor)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
float num = float.MaxValue;
int result = 0;
for (int i = 0; i < availableColors.Count; i++)
{
float num2 = ColorDistance(availableColors[i], targetColor);
if (num2 < num)
{
num = num2;
result = i;
}
}
return result;
}
private float ColorDistance(Color a, Color b)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
return Mathf.Sqrt(Mathf.Pow(a.r - b.r, 2f) + Mathf.Pow(a.g - b.g, 2f) + Mathf.Pow(a.b - b.b, 2f));
}
private void Update()
{
if (initialized && !((Object)(object)playerAvatar == (Object)null) && availableColors != null && availableColors.Count != 0 && (!SemiFunc.IsMultiplayer() || playerAvatar.photonView.IsMine))
{
timer += Time.deltaTime;
if (timer >= Instance.GetColorChangeDuration() && Instance.GetEnableColorEffect())
{
timer = 0f;
UpdateCurrentColorForMode();
ApplyColorEffect();
}
}
}
private void UpdateCurrentColorForMode()
{
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
switch (Instance.GetCurrentEffectMode())
{
case ColorEffectMode.Rainbow:
currentColorIndex = (currentColorIndex + 1) % availableColors.Count;
break;
case ColorEffectMode.PoliceSiren:
policeIndex = 1 - policeIndex;
currentColorIndex = ((policeIndex == 0) ? GetClosestColorIndex(Color.red) : GetClosestColorIndex(Color.blue));
break;
case ColorEffectMode.Strobe:
currentColorIndex = ((currentColorIndex == GetClosestColorIndex(Color.white)) ? GetClosestColorIndex(Color.black) : GetClosestColorIndex(Color.white));
break;
case ColorEffectMode.Matrix:
if (matrixIndices.Count > 0)
{
int index2 = Random.Range(0, matrixIndices.Count);
currentColorIndex = matrixIndices[index2];
}
break;
case ColorEffectMode.Sunset:
if (sunsetIndices.Count > 0)
{
int index4 = Random.Range(0, sunsetIndices.Count);
currentColorIndex = sunsetIndices[index4];
}
break;
case ColorEffectMode.Ocean:
if (oceanIndices.Count > 0)
{
int index3 = Random.Range(0, oceanIndices.Count);
currentColorIndex = oceanIndices[index3];
}
break;
case ColorEffectMode.Random:
{
int num;
do
{
num = Random.Range(0, availableColors.Count);
}
while (num == lastRandomIndex && availableColors.Count > 1);
lastRandomIndex = num;
currentColorIndex = num;
break;
}
case ColorEffectMode.Camouflage:
if (camoIndices.Count > 0)
{
int index = Random.Range(0, camoIndices.Count);
currentColorIndex = camoIndices[index];
}
break;
}
}
private void ApplyColorEffect()
{
if ((Object)(object)playerAvatar != (Object)null && availableColors != null && availableColors.Count > 0)
{
playerAvatar.PlayerAvatarSetColor(currentColorIndex);
}
}
}
private const string modGUID = "Maflingus.ColorCycler";
private const string modName = "ColorCycler";
private const string modVersion = "1.2.2";
private readonly Harmony harmony = new Harmony("Maflingus.ColorCycler");
internal ManualLogSource mls;
private ConfigEntry<float> configColorChangeDuration;
private ConfigEntry<KeyCode> configToggleKey;
private ConfigEntry<KeyCode> configCycleModeKey;
private ConfigEntry<bool> configEnabledByDefault;
private bool enableColorEffect = true;
private ConfigEntry<ColorEffectMode> configDefaultEffectMode;
private ColorEffectMode currentEffectMode;
public static ColorCycleModBase Instance { get; private set; }
private void Awake()
{
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
configColorChangeDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "ColorChangeDuration", 0.1f, "Time in seconds between color changes (lower = faster effect)");
configToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybindings", "ToggleEffectKey", (KeyCode)114, "Key to toggle color effect on/off");
configCycleModeKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybindings", "CycleModeKey", (KeyCode)109, "Key to cycle through different color effect modes");
configEnabledByDefault = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "EnabledByDefault", true, "Whether the color effect is enabled when the game starts");
configDefaultEffectMode = ((BaseUnityPlugin)this).Config.Bind<ColorEffectMode>("Settings", "DefaultEffectMode", ColorEffectMode.Rainbow, "The default color effect mode at startup");
mls = Logger.CreateLogSource("ColorCycler");
mls.LogInfo((object)"Color Effects Mod Loaded");
enableColorEffect = configEnabledByDefault.Value;
currentEffectMode = configDefaultEffectMode.Value;
mls.LogInfo((object)$"Toggle key set to: {configToggleKey.Value}");
mls.LogInfo((object)$"Cycle Mode key set to: {configCycleModeKey.Value}");
mls.LogInfo((object)$"Color change duration set to: {configColorChangeDuration.Value}s");
mls.LogInfo((object)$"Color effect enabled by default: {configEnabledByDefault.Value}");
mls.LogInfo((object)$"Default effect mode: {currentEffectMode}");
harmony.PatchAll(typeof(ColorCycleModBase));
harmony.PatchAll(typeof(PlayerAvatarPatch));
harmony.PatchAll(typeof(PlayerControllerPatch));
}
public bool GetEnableColorEffect()
{
return enableColorEffect;
}
public void ToggleColorEffect()
{
enableColorEffect = !enableColorEffect;
mls.LogInfo((object)("Color Effect: " + (enableColorEffect ? "Enabled" : "Disabled")));
ShowToggleMessage(enableColorEffect);
}
public void CycleEffectMode()
{
Array values = Enum.GetValues(typeof(ColorEffectMode));
int num = Array.IndexOf(values, currentEffectMode);
num = (num + 1) % values.Length;
currentEffectMode = (ColorEffectMode)values.GetValue(num);
mls.LogInfo((object)$"Switched to mode: {currentEffectMode}");
ShowModeChangeMessage(currentEffectMode);
}
public ColorEffectMode GetCurrentEffectMode()
{
return currentEffectMode;
}
public float GetColorChangeDuration()
{
return configColorChangeDuration.Value;
}
public KeyCode GetToggleKey()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
return configToggleKey.Value;
}
public KeyCode GetCycleModeKey()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
return configCycleModeKey.Value;
}
private void ShowToggleMessage(bool isEnabled)
{
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)MissionUI.instance != (Object)null)
{
string text = (isEnabled ? "ENABLED" : "DISABLED");
Color val = (isEnabled ? new Color(0f, 0.8f, 0f, 0.8f) : new Color(0.8f, 0f, 0f, 0.8f));
Color val2 = default(Color);
((Color)(ref val2))..ctor(1f, 1f, 0f, 0.8f);
MissionUI.instance.MissionText("COLOR EFFECT " + text, val, val2, 2f);
}
}
private void ShowModeChangeMessage(ColorEffectMode mode)
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)MissionUI.instance != (Object)null)
{
Color val = default(Color);
((Color)(ref val))..ctor(0f, 0.5f, 1f, 0.8f);
Color val2 = default(Color);
((Color)(ref val2))..ctor(1f, 1f, 0f, 0.8f);
MissionUI.instance.MissionText("MODE: " + mode.ToString().ToUpper(), val, val2, 2f);
}
}
}
[HarmonyPatch(typeof(PlayerAvatar))]
internal class PlayerAvatarPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void AddColorEffector(PlayerAvatar __instance)
{
if ((!SemiFunc.IsMultiplayer() || __instance.photonView.IsMine) && ColorCycleModBase.Instance.GetEnableColorEffect())
{
((Component)__instance).gameObject.AddComponent<ColorCycleModBase.ColorEffector>();
}
}
}
[HarmonyPatch(typeof(PlayerController))]
internal class PlayerControllerPatch
{
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void HandleKeyInput(PlayerController __instance)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)ChatManager.instance != (Object)null && ChatManager.instance.StateIsActive())
{
return;
}
if (Input.GetKeyDown(ColorCycleModBase.Instance.GetToggleKey()))
{
ColorCycleModBase.Instance.ToggleColorEffect();
PlayerAvatar componentInChildren = ((Component)__instance).GetComponentInChildren<PlayerAvatar>();
if ((Object)(object)componentInChildren != (Object)null && ColorCycleModBase.Instance.GetEnableColorEffect() && (Object)(object)((Component)componentInChildren).GetComponent<ColorCycleModBase.ColorEffector>() == (Object)null)
{
((Component)componentInChildren).gameObject.AddComponent<ColorCycleModBase.ColorEffector>();
}
}
if (Input.GetKeyDown(ColorCycleModBase.Instance.GetCycleModeKey()) && ColorCycleModBase.Instance.GetEnableColorEffect())
{
ColorCycleModBase.Instance.CycleEffectMode();
}
}
}