using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using RandomColors.Patchs;
using RandomColors.utils;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RandomColors")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("RandomColors")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a1f26bf93b0062ade091e80225a36c94c7913da6")]
[assembly: AssemblyProduct("RandomColors")]
[assembly: AssemblyTitle("RandomColors")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace RandomColors
{
[BepInPlugin("wexop.randomcolors", "RandomColors", "1.0.3")]
public class RandomColorsPlugin : BaseUnityPlugin
{
private const string GUID = "wexop.randomcolors";
private const string NAME = "RandomColors";
private const string VERSION = "1.0.3";
public static RandomColorsPlugin instance;
public List<int> saveObjectColorList = new List<int>();
public string[] themes = new string[4] { "default", "colorful", "dark", "neon" };
public ConfigEntry<bool> AffectCruiserEntry;
public ConfigEntry<bool> affectEnemyEntry;
public ConfigEntry<bool> affectFlashLight;
public ConfigEntry<bool> affectItemEntry;
public ConfigEntry<bool> affectLightEntry;
public ConfigEntry<bool> affectSunLightEntry;
public ConfigEntry<float> chanceRandomColorEntry;
public ConfigEntry<string> themeChoiceEntry;
private void Awake()
{
instance = this;
((BaseUnityPlugin)this).Logger.LogInfo((object)"RandomColors starting....");
chanceRandomColorEntry = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ChanceRandomColor", 100f, "Chance for anything that this mod affect to have random color. No need to restart the game :)");
CreateFloatConfig(chanceRandomColorEntry);
affectSunLightEntry = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AffectSunLight", false, "Sun light have a random color every day. No need to restart the game :)");
CreateBoolConfig(affectSunLightEntry);
affectLightEntry = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AffectLights", true, "Every lights in the game have a random color every day. No need to restart the game :)");
CreateBoolConfig(affectLightEntry);
affectFlashLight = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AffectFlashLight", true, "Every flashlights object have a random color on spawn. No need to restart the game :)");
CreateBoolConfig(affectFlashLight);
affectItemEntry = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AffectItems", true, "Every grabbable items in the game have a random color on spawn. No need to restart the game :)");
CreateBoolConfig(affectItemEntry);
affectEnemyEntry = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AffectEnemies", true, "Every monsters in the game have a random color on spawn. No need to restart the game :)");
CreateBoolConfig(affectEnemyEntry);
AffectCruiserEntry = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AffectCruiser", true, "Every cruiser in the game have a random color on spawn. No need to restart the game :)");
CreateBoolConfig(AffectCruiserEntry);
themeChoiceEntry = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Theme", "default", "Choose your theme ! default : any rgb color, colorful : light colors, dark : dark colors, neon : affect emissive texture color. No need to restart the game :)");
CreateDropdownConfig(themeChoiceEntry, themes);
Harmony.CreateAndPatchAll(typeof(PatchRoundManager), (string)null);
Harmony.CreateAndPatchAll(typeof(PatchGrabbableObject), (string)null);
Harmony.CreateAndPatchAll(typeof(PatchEnemyAi), (string)null);
try
{
Harmony.CreateAndPatchAll(typeof(PatchVehiculeControler), (string)null);
}
catch
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"COULD NOT LOAD VEHICULE CONTROLLER, THIS CAN HAPPEN IF YOU ARE ON VERSION < 55");
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"RandomColors is patched!");
}
private void CreateBoolConfig(ConfigEntry<bool> configEntry)
{
//IL_0002: 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_0014: Expected O, but got Unknown
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Expected O, but got Unknown
BoolCheckBoxConfigItem val = new BoolCheckBoxConfigItem(configEntry, new BoolCheckBoxOptions
{
RequiresRestart = false
});
LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val);
}
private void CreateFloatConfig(ConfigEntry<float> configEntry, float min = 0f, float max = 100f)
{
//IL_0002: 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_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
//IL_0024: Expected O, but got Unknown
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
FloatSliderOptions val = new FloatSliderOptions
{
RequiresRestart = false
};
((BaseRangeOptions<float>)val).Min = min;
((BaseRangeOptions<float>)val).Max = max;
FloatSliderConfigItem val2 = new FloatSliderConfigItem(configEntry, val);
LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2);
}
private void CreateDropdownConfig(ConfigEntry<string> configEntry, string[] values)
{
//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_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
TextDropDownConfigItem val = new TextDropDownConfigItem(configEntry, new TextDropDownOptions(Array.Empty<string>())
{
RequiresRestart = false,
Values = values
});
LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val);
}
public void SaveObjectColor(GameObject gameObject)
{
int instanceID = ((Object)gameObject).GetInstanceID();
if (!saveObjectColorList.Contains(instanceID))
{
saveObjectColorList.Add(instanceID);
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "RandomColors";
public const string PLUGIN_NAME = "RandomColors";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace RandomColors.utils
{
public class UtilsFunctions
{
public static void ChangeGameObject(GameObject gameObject)
{
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: 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_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
//IL_0153: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Expected O, but got Unknown
//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
//IL_0282: Unknown result type (might be due to invalid IL or missing references)
if (!CanChangeColor())
{
return;
}
Color? val = null;
Material val2 = null;
List<Renderer> list = gameObject.GetComponentsInChildren<Renderer>(true).ToList();
list.AddRange(gameObject.GetComponents<Renderer>());
foreach (Renderer item in list)
{
if (!((Object)(object)item != (Object)null) || !((Object)(object)item.material != (Object)null) || ((Object)((Component)item).gameObject).name.Contains("MapDot"))
{
continue;
}
Material[] materials = item.materials;
foreach (Material val3 in materials)
{
if (!val3.HasColor("_Color"))
{
continue;
}
Color val4 = GetRandomColor(val3.color.a);
if (((Object)gameObject).name.Contains("RadMech"))
{
if (val.HasValue)
{
val4 = val.Value;
}
else
{
val = val4;
}
}
try
{
val3.color = val4;
Color color = val3.GetColor("_EmissiveColor");
if (!colorDark(color))
{
if (!val.HasValue)
{
val = val4;
}
else
{
val4 = val.Value;
}
val4.a = color.a;
val3.SetColor("_EmissiveColor", val4);
RandomColorsPlugin.instance.SaveObjectColor(((Component)item).gameObject);
if ((Object)(object)val2 == (Object)null)
{
val2 = new Material(val3);
}
}
else if (RandomColorsPlugin.instance.themeChoiceEntry.Value == "neon")
{
val3.SetColor("_EmissiveColor", val4);
}
}
catch
{
}
}
}
if (!RandomColorsPlugin.instance.affectLightEntry.Value)
{
return;
}
List<Light> list2 = gameObject.GetComponentsInChildren<Light>(true).ToList();
list2.AddRange(gameObject.GetComponents<Light>());
foreach (Light item2 in list2)
{
if (!((Object)(object)item2 != (Object)null))
{
continue;
}
_ = item2.color;
if (true)
{
if (val.HasValue)
{
item2.color = val.Value;
RandomColorsPlugin.instance.SaveObjectColor(((Component)item2).gameObject);
}
else
{
item2.color = GetRandomColor(item2.color.a);
}
}
}
FlashlightItem component = gameObject.GetComponent<FlashlightItem>();
if ((Object)(object)component != (Object)null && val.HasValue && (Object)(object)val2 != (Object)null)
{
RandomColorsPlugin.instance.SaveObjectColor(((Component)component).gameObject);
component.bulbLight = val2;
}
}
public static float RandomZeroToOne()
{
return Random.Range(0f, 1f);
}
public static float RandomLightColorFloat()
{
return Random.Range(0.75f, 1f);
}
public static float RandomDarkColorFloat()
{
return Random.Range(0f, 0.25f);
}
public static Color GetRandomColor(float initialAlpha = 1f)
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
string value = RandomColorsPlugin.instance.themeChoiceEntry.Value;
Color result = default(Color);
((Color)(ref result))..ctor(RandomZeroToOne(), RandomZeroToOne(), RandomZeroToOne(), initialAlpha);
if (value == "colorful")
{
((Color)(ref result))[Random.Range(0, 4)] = RandomLightColorFloat();
}
if (value == "dark")
{
((Color)(ref result))..ctor(RandomDarkColorFloat(), RandomDarkColorFloat(), RandomDarkColorFloat());
}
return result;
}
public static bool colorDark(Color color)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: 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)
if (color.r < 2f && color.g < 2f && color.b < 2f)
{
return true;
}
return false;
}
public static bool CanChangeColor()
{
float num = Random.Range(0f, 100f);
return RandomColorsPlugin.instance.chanceRandomColorEntry.Value > num;
}
}
}
namespace RandomColors.Patchs
{
[HarmonyPatch(typeof(EnemyAI))]
public class PatchEnemyAi
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void PatchStart(EnemyAI __instance)
{
if (RandomColorsPlugin.instance.affectEnemyEntry.Value && !__instance.enemyType.enemyName.Contains("Locust Bees"))
{
UtilsFunctions.ChangeGameObject(((Component)__instance).gameObject);
}
}
}
[HarmonyPatch(typeof(GrabbableObject))]
public class PatchGrabbableObject
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void PatchStart(GrabbableObject __instance)
{
if (RandomColorsPlugin.instance.affectItemEntry.Value && (RandomColorsPlugin.instance.affectFlashLight.Value || (!((Object)((Component)__instance).gameObject).name.Contains("Flashlight") && !((Object)((Component)__instance).gameObject).name.Contains("LaserPointer"))))
{
UtilsFunctions.ChangeGameObject(((Component)__instance).gameObject);
}
}
}
[HarmonyPatch(typeof(RoundManager))]
public class PatchRoundManager
{
[HarmonyPatch("FinishedGeneratingLevelServerRpc")]
[HarmonyPostfix]
private static void PatchLoadLevel(RoundManager __instance)
{
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
if (!RandomColorsPlugin.instance.affectLightEntry.Value)
{
return;
}
List<int> list = new List<int>();
if (!RandomColorsPlugin.instance.affectSunLightEntry.Value)
{
animatedSun val = Object.FindObjectOfType<animatedSun>();
if ((Object)(object)val != (Object)null)
{
list.Add(((Object)((Component)val.directLight).gameObject).GetInstanceID());
list.Add(((Object)((Component)val.indirectLight).gameObject).GetInstanceID());
}
}
List<Light> list2 = Object.FindObjectsOfType<Light>(true).ToList();
foreach (Light item in list2)
{
if (!list.Contains(((Object)((Component)item).gameObject).GetInstanceID()) && !(((Object)item).name == "NightVision") && !RandomColorsPlugin.instance.saveObjectColorList.Contains(((Object)((Component)item).gameObject).GetInstanceID()) && UtilsFunctions.CanChangeColor())
{
item.color = UtilsFunctions.GetRandomColor(item.color.a);
}
}
}
}
[HarmonyPatch(typeof(VehicleController))]
public class PatchVehiculeControler
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void PatchStart(VehicleController __instance)
{
if (RandomColorsPlugin.instance.AffectCruiserEntry.Value)
{
UtilsFunctions.ChangeGameObject(((Component)__instance).gameObject);
}
}
}
}