Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of RandomSlimeColor v1.1.1
RandomSlimeColor.dll
Decompiled 2 years ago#define DEBUG using System; using System.Collections; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using AntlerShed.SkinRegistry; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using RandomSlimeColor.Dependencies; using RandomSlimeColor.Dependencies.EnemySkinRegistry; using RandomSlimeColor.Patches; 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("TestAccount666.RandomSlimeColor")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("Give your slimes some new colors!")] [assembly: AssemblyFileVersion("1.1.1.0")] [assembly: AssemblyInformationalVersion("1.1.1+525572b8c39e8228f195118f632b806918450d3a")] [assembly: AssemblyProduct("RandomSlimeColor")] [assembly: AssemblyTitle("TestAccount666.RandomSlimeColor")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.1.1.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [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 RandomSlimeColor { public static class Colors { internal static Random random = new Random(); internal static readonly Color[] GetColors = (Color[])(object)new Color[9] { Color.black, Color.white, Color.blue, Color.green, Color.cyan, Color.gray, Color.magenta, Color.red, Color.yellow }; internal static int GetRandomColorIndex() { return random.Next(0, GetColors.Length + 1); } internal static int GetRandomColorIndexWithoutRainbow() { return random.Next(0, GetColors.Length); } } public static class ConfigManager { internal static ConfigEntry<float> rainbowSpeedMultiplier; internal static void Setup(ConfigFile configFile) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown rainbowSpeedMultiplier = configFile.Bind<float>("General", "Rainbow Speed Multiplier", 6f, new ConfigDescription("Defines the multiplier that is applied to the rainbow slime's color changing", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 20f), Array.Empty<object>())); } } public class RainbowSlime : MonoBehaviour { private static readonly int _GradientColorProperty = Shader.PropertyToID("_Gradient_Color"); internal BlobAI? blobAI; private float _hue; private void LateUpdate() { //IL_0047: Unknown result type (might be due to invalid IL or missing references) if (blobAI != null) { float num = 0.01f * Time.deltaTime * ConfigManager.rainbowSpeedMultiplier.Value; blobAI.thisSlimeMaterial.SetColor(_GradientColorProperty, Color.HSVToRGB(_hue, 1f, 1f)); _hue += num; if (_hue >= 1f) { _hue = 0f; } } } } [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("TestAccount666.RandomSlimeColor", "RandomSlimeColor", "1.1.1")] public class RandomSlimeColor : BaseUnityPlugin { private static bool _enemyRegistryInstalled; public static RandomSlimeColor Instance { get; private set; } internal static ManualLogSource Logger { get; private set; } internal static Harmony? Harmony { get; set; } private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; Instance = this; ConfigManager.Setup(((BaseUnityPlugin)this).Config); _enemyRegistryInstalled = DependencyChecker.IsEnemySkinRegistryInstalled(); Patch(); if (_enemyRegistryInstalled) { Assembly executingAssembly = Assembly.GetExecutingAssembly(); string directoryName = Path.GetDirectoryName(executingAssembly.Location); Debug.Assert(directoryName != null, "assemblyDirectory != null"); string path = Path.Combine(directoryName, "randomslimecolor"); AssetLoader.LoadAssetBundle(path); AssetLoader.LoadAssets(); EnemySkinRegistrySupport.Initialize(); } Logger.LogInfo((object)"TestAccount666.RandomSlimeColor v1.1.1 has loaded!"); } internal static void Patch() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown if (Harmony == null) { Harmony = new Harmony("TestAccount666.RandomSlimeColor"); } Logger.LogDebug((object)"Patching..."); Harmony.PatchAll(typeof(RoundManagerPatch)); if (!_enemyRegistryInstalled) { Harmony.PatchAll(typeof(BlobPatch)); } Logger.LogDebug((object)"Finished patching!"); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "TestAccount666.RandomSlimeColor"; public const string PLUGIN_NAME = "RandomSlimeColor"; public const string PLUGIN_VERSION = "1.1.1"; } } namespace RandomSlimeColor.Patches { [HarmonyPatch(typeof(BlobAI))] public class BlobPatch { private static readonly int _GradientColorProperty = Shader.PropertyToID("_Gradient_Color"); [HarmonyPatch("Start")] [HarmonyPostfix] [HarmonyAfter(new string[] { "Tomato.SCP999", "Tomato.LeanCompany" })] private static void AfterBlobStart(BlobAI __instance) { //IL_0031: 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) //IL_0042: Unknown result type (might be due to invalid IL or missing references) int randomColorIndex = Colors.GetRandomColorIndex(); if (randomColorIndex == Colors.GetColors.Length) { RainbowSlime rainbowSlime = ((Component)__instance).gameObject.AddComponent<RainbowSlime>(); rainbowSlime.blobAI = __instance; } else { Color val = Colors.GetColors[randomColorIndex]; __instance.thisSlimeMaterial.SetColor(_GradientColorProperty, val); } } } [HarmonyPatch(typeof(RoundManager))] public static class RoundManagerPatch { [HarmonyPatch("GenerateNewLevelClientRpc")] [HarmonyPostfix] private static void OnNewRandomSeed(int randomSeed) { Colors.random = new Random(randomSeed); RandomSlimeColor.Logger.LogInfo((object)$"Chose new seed for slime random: {randomSeed}"); } } } namespace RandomSlimeColor.Dependencies { public static class DependencyChecker { public static bool IsEnemySkinRegistryInstalled() { return Chainloader.PluginInfos.Values.Any((PluginInfo metadata) => metadata.Metadata.GUID.Contains("antlershed.lethalcompany.enemyskinregistry")); } } } namespace RandomSlimeColor.Dependencies.EnemySkinRegistry { public static class AssetLoader { private static AssetBundle? _assetBundle; public static Texture2D randomColorTexture; public static Texture2D rainbowColorTexture; public static void LoadAssetBundle(string path) { _assetBundle = AssetBundle.LoadFromFile(path); } public static void LoadAssets() { if (!((Object)(object)_assetBundle == (Object)null)) { randomColorTexture = _assetBundle.LoadAsset<Texture2D>("Assets/LethalCompany/Mods/RandomSlimeColors/RandomColorTexture.png"); rainbowColorTexture = _assetBundle.LoadAsset<Texture2D>("Assets/LethalCompany/Mods/RandomSlimeColors/RainbowColorTexture.png"); } } } public static class EnemySkinRegistrySupport { public static void Initialize() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) EnemySkinRegistry.RegisterSkin((Skin)(object)new RandomSlimeColorSkin(), (DefaultSkinConfigData?)new DefaultSkinConfigData { defaultEntries = Array.Empty<DefaultSkinConfigEntry>(), defaultIndoorFrequency = 0.75f, defaultOutdoorFrequency = 0.75f, vanillaFallbackIndoorFrequency = 0f, vanillaFallbackOutdoorFrequency = 0f }); EnemySkinRegistry.RegisterSkin((Skin)(object)new RainbowSlimeColorSkin(), (DefaultSkinConfigData?)new DefaultSkinConfigData { defaultEntries = Array.Empty<DefaultSkinConfigEntry>(), defaultIndoorFrequency = 0.25f, defaultOutdoorFrequency = 0.25f, vanillaFallbackIndoorFrequency = 0f, vanillaFallbackOutdoorFrequency = 0f }); } } public class RainbowSlimeColorSkin : Skin { public string Label => "Rainbow Color"; public string Id => "TestAccount666.RainbowSlimeColor"; public string EnemyId => "LethalCompany.Hygrodere"; public Texture2D Icon => AssetLoader.rainbowColorTexture; public Skinner CreateSkinner() { return (Skinner)(object)new RainbowSlimeColorSkinner(); } } public class RainbowSlimeColorSkinner : Skinner { private static readonly int _GradientColorProperty = Shader.PropertyToID("_Gradient_Color"); public Color? previousColor; public void Apply(GameObject enemy) { BlobAI component = enemy.GetComponent<BlobAI>(); ((MonoBehaviour)component).StartCoroutine(WaitAndApplySkin(component)); } public void Remove(GameObject enemy) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) if (previousColor.HasValue) { BlobAI component = enemy.GetComponent<BlobAI>(); RainbowSlime rainbowSlime = ((Component)component).gameObject.AddComponent<RainbowSlime>(); Object.Destroy((Object)(object)rainbowSlime); component.thisSlimeMaterial.SetColor(_GradientColorProperty, previousColor.Value); } } public IEnumerator WaitAndApplySkin(BlobAI blobAI) { BlobAI blobAI2 = blobAI; yield return (object)new WaitUntil((Func<bool>)(() => Object.op_Implicit((Object)(object)blobAI2.thisSlimeMaterial))); previousColor = blobAI2.thisSlimeMaterial.GetColor(_GradientColorProperty); RainbowSlime rainbowSlime = ((Component)blobAI2).gameObject.AddComponent<RainbowSlime>(); rainbowSlime.blobAI = blobAI2; } } public class RandomSlimeColorSkin : Skin { public string Label => "Random Color"; public string Id => "TestAccount666.RandomSlimeColor"; public string EnemyId => "LethalCompany.Hygrodere"; public Texture2D Icon => AssetLoader.randomColorTexture; public Skinner CreateSkinner() { return (Skinner)(object)new RandomSlimeColorSkinner(); } } public class RandomSlimeColorSkinner : Skinner { private static readonly int _GradientColorProperty = Shader.PropertyToID("_Gradient_Color"); public Color? previousColor; public void Apply(GameObject enemy) { BlobAI component = enemy.GetComponent<BlobAI>(); ((MonoBehaviour)component).StartCoroutine(WaitAndApplySkin(component)); } public void Remove(GameObject enemy) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) if (previousColor.HasValue) { BlobAI component = enemy.GetComponent<BlobAI>(); component.thisSlimeMaterial.SetColor(_GradientColorProperty, previousColor.Value); } } public IEnumerator WaitAndApplySkin(BlobAI blobAI) { BlobAI blobAI2 = blobAI; yield return (object)new WaitUntil((Func<bool>)(() => Object.op_Implicit((Object)(object)blobAI2.thisSlimeMaterial))); previousColor = blobAI2.thisSlimeMaterial.GetColor(_GradientColorProperty); int colorIndex = Colors.GetRandomColorIndexWithoutRainbow(); Color color = Colors.GetColors[colorIndex]; blobAI2.thisSlimeMaterial.SetColor(_GradientColorProperty, color); } } }