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 RickSanchez v1.1.0
RickSanchez.dll
Decompiled a year ago#define DEBUG using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using LethalLib.Modules; using Microsoft.CodeAnalysis; using RickSanchez.Configuration; using RickSanchez.NetcodePatcher; using Unity.Netcode; 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("RickSanchez")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("Rick Sanchez for Lethal Company.")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+4c52dcfb7b1692504bab67d3aa07fb5c5f262b52")] [assembly: AssemblyProduct("RickSanchez")] [assembly: AssemblyTitle("RickSanchez")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] [module: NetcodePatchedAssembly] internal class <Module> { static <Module>() { } } 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 RickSanchez { [BepInPlugin("hamunii.RickSanchez", "RickSanchez", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string ModGUID = "hamunii.RickSanchez"; internal static ManualLogSource Logger; public static AssetBundle ModAssets; internal static PluginConfig BoundConfig { get; private set; } private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; BoundConfig = new PluginConfig((BaseUnityPlugin)(object)this); InitializeNetworkBehaviours(); string path = "rickassets"; ModAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), path)); if ((Object)(object)ModAssets == (Object)null) { Logger.LogError((object)"Failed to load custom assets."); return; } EnemyType val = ModAssets.LoadAsset<EnemyType>("RickSanchez"); TerminalNode val2 = ModAssets.LoadAsset<TerminalNode>("RickSanchezTN"); TerminalKeyword val3 = ModAssets.LoadAsset<TerminalKeyword>("RickSanchezTK"); NetworkPrefabs.RegisterNetworkPrefab(val.enemyPrefab); Enemies.RegisterEnemy(val, BoundConfig.SpawnWeight.Value, (LevelTypes)(-1), (SpawnType)0, val2, val3); Logger.LogInfo((object)"Plugin RickSanchez is loaded!"); } private static void InitializeNetworkBehaviours() { Type[] types = Assembly.GetExecutingAssembly().GetTypes(); Type[] array = types; foreach (Type type in array) { MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic); MethodInfo[] array2 = methods; foreach (MethodInfo methodInfo in array2) { object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false); if (customAttributes.Length != 0) { methodInfo.Invoke(null, null); } } } } } internal class RickSanchezAI : EnemyAI { private enum State { SearchingForPlayer, StickingInFrontOfPlayer, HeadSwingAttackInProgress } public Transform turnCompass; public Transform attackArea; private float timeSinceHittingLocalPlayer; private float timeSinceNewRandPos; public float rickTimer; public float foundTimer; private bool stalkAudio; private float rickrange; private Vector3 positionRandomness; private Vector3 StalkPos; private Random enemyRandom; private bool isDeadAnimationDone; [Conditional("DEBUG")] private void LogIfDebugBuild(string text) { Plugin.Logger.LogInfo((object)text); } public override void Start() { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) ((EnemyAI)this).Start(); LogIfDebugBuild("Rick Sanchez Spawned"); rickTimer = 0f; foundTimer = 0f; timeSinceHittingLocalPlayer = 0f; timeSinceNewRandPos = 0f; positionRandomness = new Vector3(0f, 0f, 0f); enemyRandom = new Random(StartOfRound.Instance.randomMapSeed + base.thisEnemyIndex); isDeadAnimationDone = false; rickrange = 10f; stalkAudio = true; base.currentBehaviourStateIndex = 0; ((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null); base.agent.speed = 3f; } public override void Update() { //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) ((EnemyAI)this).Update(); if (base.isEnemyDead) { for (int i = 0; i < 4; i++) { StartOfRound.Instance.allPlayerScripts[i].movementSpeed = 5f; } base.creatureVoice.Stop(); base.creatureVoice.PlayOneShot(base.dieSFX); return; } rickTimer -= Time.deltaTime; if ((double)rickTimer <= 0.0) { rickTimer = Random.Range(10f, 20f); base.creatureSFX.Play(); } timeSinceHittingLocalPlayer += Time.deltaTime; timeSinceNewRandPos += Time.deltaTime; int currentBehaviourStateIndex = base.currentBehaviourStateIndex; if (base.stunNormalizedTimer > 0f) { base.agent.speed = 0f; } if (FoundClosestPlayerInRange(25f, 7f)) { ((EnemyAI)this).StopSearch(base.currentSearch, true); if (stalkAudio) { base.creatureVoice.Play(); } stalkAudio = false; foundTimer -= Time.deltaTime; if (foundTimer <= 0f) { LogIfDebugBuild("Start Target Player"); stalkAudio = true; foundTimer = 15f; } } if (HasValidTarget()) { LogIfDebugBuild("Has Valid Target"); StalkPos = ((Component)base.targetPlayer).transform.position - Vector3.Scale(new Vector3(-1f, 0f, -1f), ((Component)base.targetPlayer).transform.forward); base.targetPlayer.movementSpeed = 0f; ((EnemyAI)this).SetDestinationToPosition(StalkPos, false); } else { base.targetPlayer = null; } } public override void DoAIInterval() { ((EnemyAI)this).DoAIInterval(); if (!base.isEnemyDead && !StartOfRound.Instance.allPlayersDead) { } } private bool FoundClosestPlayerInRange(float range, float senseRange) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) ((EnemyAI)this).TargetClosestPlayer(range, true, 70f); if ((Object)(object)base.targetPlayer == (Object)null) { ((EnemyAI)this).TargetClosestPlayer(senseRange, false, 70f); range = senseRange; } return (Object)(object)base.targetPlayer != (Object)null && Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) < range; } private bool TargetClosestPlayerInAnyCase() { //IL_001f: 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) base.mostOptimalDistance = 2000f; base.targetPlayer = null; for (int i = 0; i < StartOfRound.Instance.connectedPlayersAmount + 1; i++) { base.tempDist = Vector3.Distance(((Component)this).transform.position, ((Component)StartOfRound.Instance.allPlayerScripts[i]).transform.position); if (base.tempDist < base.mostOptimalDistance) { base.mostOptimalDistance = base.tempDist; base.targetPlayer = StartOfRound.Instance.allPlayerScripts[i]; } } if ((Object)(object)base.targetPlayer == (Object)null) { return false; } return true; } private void StickingInFrontOfPlayer() { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: 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_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: 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_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)base.targetPlayer == (Object)null) && ((NetworkBehaviour)this).IsOwner) { if (timeSinceNewRandPos > 0.7f) { timeSinceNewRandPos = 0f; LogIfDebugBuild("Gliding to Target Player"); } positionRandomness = new Vector3((float)enemyRandom.Next(-1, 1), 0f, (float)enemyRandom.Next(-1, 1)); StalkPos = ((Component)base.targetPlayer).transform.position - Vector3.Scale(new Vector3(-5f, 0f, -5f), ((Component)base.targetPlayer).transform.forward) + positionRandomness; ((EnemyAI)this).SetDestinationToPosition(StalkPos, false); } } private IEnumerator SwingAttack() { LogIfDebugBuild("Swing Attack"); ((EnemyAI)this).SwitchToBehaviourClientRpc(2); StalkPos = ((Component)base.targetPlayer).transform.position; ((EnemyAI)this).SetDestinationToPosition(StalkPos, false); yield return (object)new WaitForSeconds(0.5f); if (!base.isEnemyDead) { yield return (object)new WaitForSeconds(0.35f); if (base.currentBehaviourStateIndex == 2) { ((EnemyAI)this).SwitchToBehaviourClientRpc(1); } } } private bool HasValidTarget() { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) return (Object)(object)base.targetPlayer != (Object)null && base.targetPlayer.isInsideFactory && !base.targetPlayer.isPlayerDead && Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) < rickrange; } public override void OnCollideWithPlayer(Collider other) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) if (!(timeSinceHittingLocalPlayer < 5f) && !base.isEnemyDead) { PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false); if (!((Object)(object)val == (Object)null)) { timeSinceHittingLocalPlayer = 0f; val.DamagePlayer(100, true, true, (CauseOfDeath)0, 0, false, default(Vector3)); base.creatureVoice.Stop(); base.agent.speed = 3f; base.creatureVoice.PlayOneShot(base.dieSFX); ((EnemyAI)this).KillEnemyOnOwnerClient(false); } } } public override void HitEnemy(int force = 2, PlayerControllerB playerWhoHit = null, bool playHitSFX = true, int hitID = -1) { ((EnemyAI)this).HitEnemy(force, playerWhoHit, playHitSFX, -1); LogIfDebugBuild("Rick has been hit"); if (base.isEnemyDead) { return; } base.enemyHP -= force; if (((NetworkBehaviour)this).IsOwner && base.enemyHP <= 0 && !base.isEnemyDead) { for (int i = 0; i < 4; i++) { StartOfRound.Instance.allPlayerScripts[i].movementSpeed = 5f; } base.creatureVoice.PlayOneShot(base.dieSFX); ((EnemyAI)this).KillEnemyOnOwnerClient(false); } } protected override void __initializeVariables() { ((EnemyAI)this).__initializeVariables(); } protected internal override string __getTypeName() { return "RickSanchezAI"; } } public static class PluginInfo { public const string PLUGIN_GUID = "RickSanchez"; public const string PLUGIN_NAME = "RickSanchez"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace RickSanchez.Configuration { public class PluginConfig { public ConfigEntry<int> SpawnWeight; public PluginConfig(BaseUnityPlugin plugin) { SpawnWeight = plugin.Config.Bind<int>("RickSanchez", "Spawn weight", 1000, "The spawn chance weight for RickSanchez, relative to other existing enemies.\nGoes up from 0, lower is more rare, 100 and up is very common."); ClearUnusedEntries(plugin); } private void ClearUnusedEntries(BaseUnityPlugin plugin) { PropertyInfo property = ((object)plugin.Config).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic); Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(plugin.Config, null); dictionary.Clear(); plugin.Config.Save(); } } } namespace RickSanchez.NetcodePatcher { [AttributeUsage(AttributeTargets.Module)] internal class NetcodePatchedAssemblyAttribute : Attribute { } }