Please disclose if your mod was created primarily 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 Diversity v1.0.2
Diversity/Diversity.dll
Decompiled 2 years agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Diversity.Monsters; using Diversity.Patches; using Diversity.Player; using GameNetcodeStuff; using HarmonyLib; using LethalLib.Modules; using Microsoft.CodeAnalysis; using Unity.Netcode; using UnityEngine; using UnityEngine.Events; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("Diversity")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Diversity")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("6163c54c-2d5b-4683-ac86-9337d16cc4fd")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] 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; } } } namespace Diversity { public class Configuration { public static ConfigEntry<bool> spiderRevamp; public static ConfigEntry<float> spiderSlowAmount; public static ConfigEntry<bool> crawlerRevamp; public static ConfigEntry<float> crawlerSlowAmount; public static ConfigEntry<bool> centipedeRevamp; public static ConfigEntry<int> clickAmount; public static ConfigEntry<bool> playerRegen; public static ConfigEntry<bool> playerDying; public static void Load() { spiderRevamp = Diversity.config.Bind<bool>("Monster", "SpiderRevamp", true, "Should spider revamp be enabled?"); spiderSlowAmount = Diversity.config.Bind<float>("Monster", "SpiderSlow", 0.8f, "How much slown should spiders be on hit?"); crawlerRevamp = Diversity.config.Bind<bool>("Monster", "CrawlerRevamp", true, "Should crawler revamp be enabled?"); crawlerSlowAmount = Diversity.config.Bind<float>("Monster", "CrawlerSlow", 0.9f, "How much slown should crawlers be on hit?"); centipedeRevamp = Diversity.config.Bind<bool>("Monster", "CentipedeRevamp", true, "Should centipede revamp be enabled?"); clickAmount = Diversity.config.Bind<int>("Monster", "ClickAmount", 25, "How many times should you have to click to remove the centipede from someone's head?"); playerRegen = Diversity.config.Bind<bool>("Player", "PlayerRegen", false, "Should players be able to regen?"); playerDying = Diversity.config.Bind<bool>("Player", "PlayerDying", false, "Should a custom player dying sound be enabled?"); } } public class Content { public class CustomItem { public string name = ""; public string itemPath = ""; public string infoPath = ""; public Action<Item> itemAction = delegate { }; public bool enabled = true; public CustomItem(string name, string itemPath, string infoPath, Action<Item> action = null) { this.name = name; this.itemPath = itemPath; this.infoPath = infoPath; if (action != null) { itemAction = action; } } public static CustomItem Add(string name, string itemPath, string infoPath = null, Action<Item> action = null) { return new CustomItem(name, itemPath, infoPath, action); } } public class CustomShopItem : CustomItem { public int itemPrice; public CustomShopItem(string name, string itemPath, string infoPath = null, int itemPrice = 0, Action<Item> action = null) : base(name, itemPath, infoPath, action) { this.itemPrice = itemPrice; } public static CustomShopItem Add(string name, string itemPath, string infoPath = null, int itemPrice = 0, Action<Item> action = null, bool enabled = true) { return new CustomShopItem(name, itemPath, infoPath, itemPrice, action) { enabled = enabled }; } } public static AssetBundle MainAssets; public static List<CustomItem> customItems; public static Dictionary<string, GameObject> Prefabs = new Dictionary<string, GameObject>(); public static void TryLoadAssets() { if ((Object)(object)MainAssets == (Object)null) { MainAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "diversity")); Diversity.mls.LogInfo((object)"Loaded asset bundle"); } } public static void Load() { TryLoadAssets(); customItems = new List<CustomItem> { CustomShopItem.Add("Bandages", "assets/custom/diversity/bandage.prefab", "assets/custom/diversity/bandageinfo.json", 25) }; foreach (CustomItem customItem in customItems) { if (customItem.enabled) { Item val = MainAssets.LoadAsset<Item>(customItem.itemPath); if (customItem is CustomShopItem) { TerminalNode val2 = MainAssets.LoadAsset<TerminalNode>(customItem.infoPath); Diversity.mls.LogInfo((object)$"Registering shop item {customItem.name} with price {((CustomShopItem)customItem).itemPrice}"); Items.RegisterShopItem(val, (TerminalNode)null, (TerminalNode)null, val2, ((CustomShopItem)customItem).itemPrice); } } } Diversity.mls.LogInfo((object)"Custom content loaded!"); } } [BepInPlugin("Chaos.Diversity", "Diversity", "1.0.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Diversity : BaseUnityPlugin { private const string modGUID = "Chaos.Diversity"; private const string modName = "Diversity"; private const string modVersion = "1.0.2"; private readonly Harmony harmony = new Harmony("Chaos.Diversity"); public static Diversity Instance; public static ManualLogSource mls; public static ConfigFile config; private void Awake() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown if ((Object)(object)Instance == (Object)null) { Instance = this; } mls = ((BaseUnityPlugin)this).Logger; config = ((BaseUnityPlugin)this).Config; Configuration.Load(); Content.TryLoadAssets(); GameObject val = new GameObject("Diversity"); val.AddComponent<DiversityBehaviour>(); ((Object)val).hideFlags = (HideFlags)61; Object.DontDestroyOnLoad((Object)(object)val); mls.LogInfo((object)"Diversity GameObject created."); harmony.PatchAll(typeof(Diversity)); harmony.PatchAll(typeof(PlayerControllerBPatch)); harmony.PatchAll(typeof(SandSpiderAIPatch)); harmony.PatchAll(typeof(CrawlerAIPatch)); mls.LogInfo((object)"Diversity started."); } } public class DiversityBehaviour : MonoBehaviour { public void Update() { SandSpiderAI[] array = (SandSpiderAI[])(object)Object.FindObjectsOfType(typeof(SandSpiderAI)); if (Configuration.spiderRevamp.Value) { SandSpiderAI[] array2 = array; foreach (SandSpiderAI val in array2) { if ((Object)(object)((Component)val).gameObject.GetComponent<SpiderRevamp>() == (Object)null) { ((Component)val).gameObject.AddComponent<SpiderRevamp>(); Diversity.mls.LogInfo((object)("Added SpiderRevamp to: " + ((Object)((Component)val).gameObject).name)); } } } CrawlerAI[] array3 = (CrawlerAI[])(object)Object.FindObjectsOfType(typeof(CrawlerAI)); if (Configuration.crawlerRevamp.Value) { CrawlerAI[] array4 = array3; foreach (CrawlerAI val2 in array4) { if ((Object)(object)((Component)val2).gameObject.GetComponent<CrawlerRevamp>() == (Object)null) { ((Component)val2).gameObject.AddComponent<CrawlerRevamp>(); Diversity.mls.LogInfo((object)("Added CrawlerRevamp to: " + ((Object)((Component)val2).gameObject).name)); } } } PlayerControllerB[] array5 = (PlayerControllerB[])(object)Object.FindObjectsOfType(typeof(PlayerControllerB)); if (Configuration.playerDying.Value) { PlayerControllerB[] array6 = array5; foreach (PlayerControllerB val3 in array6) { if ((Object)(object)((Component)val3).gameObject.GetComponent<PlayerDying>() == (Object)null) { ((Component)val3).gameObject.AddComponent<PlayerDying>(); Diversity.mls.LogInfo((object)("Added PlayerDying to: " + ((Object)((Component)val3).gameObject).name)); } } } CentipedeAI[] array7 = (CentipedeAI[])(object)Object.FindObjectsOfType(typeof(CentipedeAI)); if (!Configuration.centipedeRevamp.Value) { return; } CentipedeAI[] array8 = array7; foreach (CentipedeAI val4 in array8) { if ((Object)(object)((Component)val4).gameObject.GetComponent<CentipedeRevamp>() == (Object)null) { ((Component)val4).gameObject.AddComponent<CentipedeRevamp>(); Diversity.mls.LogInfo((object)("Added CentipedeRevamp to: " + ((Object)((Component)val4).gameObject).name)); } } } } } namespace Diversity.Player { internal class PlayerDying : MonoBehaviour { private PlayerControllerB player; private AudioSource audio; private GameObject obj; private void Start() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown obj = new GameObject("DyingAudio"); player = ((Component)this).gameObject.GetComponent<PlayerControllerB>(); obj.transform.SetParent(((Component)player.thisPlayerBody).gameObject.transform); audio = obj.gameObject.AddComponent<AudioSource>(); ((Behaviour)audio).enabled = false; audio.loop = true; audio.playOnAwake = true; audio.clip = Content.MainAssets.LoadAsset<AudioClip>("assets/custom/diversity/audio/player/dying.mp3"); audio.spatialBlend = 1f; audio.minDistance = 5f; audio.maxDistance = 15f; audio.volume = 1f; audio.rolloffMode = (AudioRolloffMode)1; audio.bypassEffects = true; audio.bypassListenerEffects = true; } } } namespace Diversity.Patches { internal class CrawlerAIPatch { private static CrawlerRevamp crawler; [HarmonyPatch(typeof(CrawlerAI), "HitEnemy")] [HarmonyPrefix] public static void Slow(CrawlerAI __instance) { crawler = ((Component)__instance).GetComponent<CrawlerRevamp>(); if (Object.op_Implicit((Object)(object)crawler) && !crawler.onCooldown) { crawler.hasBeenhit = true; crawler.onCooldown = true; crawler.previousAgentSpeed = ((EnemyAI)__instance).agent.speed; crawler.previousAgentAcceleration = ((EnemyAI)__instance).agent.acceleration; crawler.currentAgentSpeed = ((EnemyAI)__instance).agent.speed; crawler.currentAgentAcceleration = ((EnemyAI)__instance).agent.acceleration; Diversity.mls.LogInfo((object)"Crawler hit!"); } } } [HarmonyPatch(typeof(PlayerControllerB))] public class PlayerControllerBPatch { private static AudioSource audio; [HarmonyPatch("Update")] [HarmonyPostfix] private static void regenDisabled(ref float ___healthRegenerateTimer) { if (!Configuration.playerRegen.Value) { ___healthRegenerateTimer = 1f; } } [HarmonyPatch(typeof(PlayerControllerB), "Update")] [HarmonyPostfix] private static void Dying(PlayerControllerB __instance, ref int ___health) { if (!Object.op_Implicit((Object)(object)((Component)__instance.thisPlayerBody).transform.Find("DyingAudio")) || !Configuration.playerDying.Value) { return; } audio = ((Component)((Component)__instance.thisPlayerBody).transform.Find("DyingAudio")).GetComponent<AudioSource>(); if (Object.op_Implicit((Object)(object)audio)) { if (___health < 20) { ((Behaviour)audio).enabled = true; } else { ((Behaviour)audio).enabled = false; } } } } [HarmonyPatch(typeof(SandSpiderAI))] internal class SandSpiderAIPatch { private static SpiderRevamp spider; [HarmonyPatch(typeof(SandSpiderAI), "HitEnemy")] [HarmonyPrefix] public static void Slow(SandSpiderAI __instance) { spider = ((Component)__instance).GetComponent<SpiderRevamp>(); if (Object.op_Implicit((Object)(object)spider) && !spider.onCooldown) { spider.hasBeenhit = true; spider.onCooldown = true; spider.previousAgentSpeed = ((EnemyAI)__instance).agent.speed; spider.previousSpiderSpeed = __instance.spiderSpeed; spider.currentAgentSpeed = ((EnemyAI)__instance).agent.speed; spider.currentSpiderSpeed = __instance.spiderSpeed; Diversity.mls.LogInfo((object)"Spider hit!"); } } } } namespace Diversity.Monsters { public class CentipedeRevamp : MonoBehaviour { private CentipedeAI centipede; private InteractTrigger centipedeInteractTrigger; public int clicks; private void Start() { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Expected O, but got Unknown centipede = ((Component)this).gameObject.GetComponent<CentipedeAI>(); GameObject val = Object.Instantiate<GameObject>(Content.MainAssets.LoadAsset<GameObject>("assets/custom/centipede/interactobject.prefab"), new Vector3(0f, 0f, 0f), Quaternion.identity); val.GetComponent<NetworkObject>().Spawn(true); Diversity.mls.LogInfo((object)"Loaded centipede prefab!"); val.transform.SetParent(((Component)this).transform); Diversity.mls.LogInfo((object)"Appended centipede prefab!"); centipedeInteractTrigger = val.GetComponent<InteractTrigger>(); Diversity.mls.LogInfo((object)"InteractTrigger fetched!"); centipedeInteractTrigger.interactable = true; centipedeInteractTrigger.onInteract = new InteractEvent(); ((UnityEvent<PlayerControllerB>)(object)centipedeInteractTrigger.onInteract).AddListener((UnityAction<PlayerControllerB>)Free); } public void Free(PlayerControllerB player) { Diversity.mls.LogInfo((object)"Player interacted with a centipede!"); } private void Update() { if (Object.op_Implicit((Object)(object)centipede) && (Object)(object)centipede.clingingToPlayer != (Object)null) { Diversity.mls.LogInfo((object)"Centipede latched on head!!"); } } } public class CrawlerRevamp : MonoBehaviour { private CrawlerAI crawler; private static float slowAmount = Configuration.crawlerSlowAmount.Value; private static float timeElapsed = 0f; private static float cooldown = 0f; public bool onCooldown = false; public bool hasBeenhit = false; public float previousAgentSpeed = 0f; public float previousAgentAcceleration = 0f; public float currentAgentSpeed = 0f; public float currentAgentAcceleration = 0f; private void Start() { crawler = ((Component)this).gameObject.GetComponent<CrawlerAI>(); } private void Update() { if (!Object.op_Implicit((Object)(object)crawler)) { return; } if (hasBeenhit) { if (timeElapsed < 2f) { currentAgentSpeed = Mathf.Lerp(currentAgentSpeed - currentAgentSpeed * slowAmount, previousAgentSpeed, timeElapsed / 2f); currentAgentAcceleration = Mathf.Lerp(currentAgentAcceleration - currentAgentAcceleration * slowAmount, previousAgentAcceleration + 5f, timeElapsed / 2f); timeElapsed += Time.deltaTime; Diversity.mls.LogInfo((object)("Time elapsed: " + timeElapsed)); } else { currentAgentSpeed = previousAgentSpeed; currentAgentAcceleration = previousAgentAcceleration; } if (currentAgentSpeed == previousAgentSpeed) { hasBeenhit = false; } ((EnemyAI)crawler).agent.speed = currentAgentSpeed; ((EnemyAI)crawler).agent.acceleration = currentAgentAcceleration; } if (onCooldown) { cooldown += Time.deltaTime; } if (onCooldown && cooldown > 2f && hasBeenhit) { Diversity.mls.LogInfo((object)"Crawler debuff hit is over."); hasBeenhit = false; timeElapsed = 0f; } if (onCooldown && cooldown > 3f) { Diversity.mls.LogInfo((object)"Crawler debuff cooldown is over."); onCooldown = false; cooldown = 0f; } } } public class SpiderRevamp : MonoBehaviour { private SandSpiderAI spider; private static float slowAmount = Configuration.spiderSlowAmount.Value; private static float timeElapsed = 0f; private static float cooldown = 0f; public bool onCooldown = false; public bool hasBeenhit = false; public float previousAgentSpeed = 0f; public float previousSpiderSpeed = 0f; public float currentAgentSpeed = 0f; public float currentSpiderSpeed = 0f; private void Start() { spider = ((Component)this).gameObject.GetComponent<SandSpiderAI>(); } private void Update() { if (!Object.op_Implicit((Object)(object)spider)) { return; } if (hasBeenhit) { if (timeElapsed < 1f) { currentSpiderSpeed = Mathf.Lerp(currentSpiderSpeed - currentSpiderSpeed * slowAmount, previousSpiderSpeed, timeElapsed / 1f); currentAgentSpeed = Mathf.Lerp(currentAgentSpeed - currentAgentSpeed * slowAmount, previousAgentSpeed, timeElapsed / 1f); timeElapsed += Time.deltaTime; Diversity.mls.LogInfo((object)("Time elapsed: " + timeElapsed)); } else { currentSpiderSpeed = previousSpiderSpeed; currentAgentSpeed = previousAgentSpeed; } if (currentSpiderSpeed == previousSpiderSpeed) { hasBeenhit = false; } spider.spiderSpeed = currentSpiderSpeed; ((EnemyAI)spider).agent.speed = currentAgentSpeed; if (currentSpiderSpeed > 0f) { ((EnemyAI)spider).creatureAnimator.SetBool("moving", true); } else { ((EnemyAI)spider).creatureAnimator.SetBool("moving", false); } } if (onCooldown) { cooldown += Time.deltaTime; } if (onCooldown && cooldown > 1f && hasBeenhit) { Diversity.mls.LogInfo((object)"Spider debuff hit is over."); hasBeenhit = false; timeElapsed = 0f; } if (onCooldown && cooldown > 3f) { Diversity.mls.LogInfo((object)"Spider debuff cooldown is over."); onCooldown = false; cooldown = 0f; } } } } namespace Diversity.Items { public class Bandages : GrabbableObject { private PlayerControllerB previousPlayerHeldBy; public override void ItemActivate(bool used, bool buttonDown = true) { ((GrabbableObject)this).ItemActivate(used, buttonDown); if (((NetworkBehaviour)this).IsOwner) { Heal(); } } public override void EquipItem() { ((GrabbableObject)this).EquipItem(); if ((Object)(object)base.playerHeldBy != (Object)null) { previousPlayerHeldBy = base.playerHeldBy; } } private void Heal() { previousPlayerHeldBy.health = Mathf.Clamp(previousPlayerHeldBy.health + 20, 0, 100); ((GrabbableObject)this).DestroyObjectInHand(previousPlayerHeldBy); } } }