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 Mett2 v1.0.3
plugins/Mett2/Doentis.Mett2.dll
Decompiled 9 months agousing 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 Doentis.Mett2.NetcodePatcher; using ExampleEnemy.Configuration; using GameNetcodeStuff; using LethalLib.Modules; using Microsoft.CodeAnalysis; using Unity.Netcode; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Doentis.Mett2")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.3.0")] [assembly: AssemblyInformationalVersion("1.0.3+0864a05544691c96bb0f101813317f1ce77b7629")] [assembly: AssemblyProduct("Mett2")] [assembly: AssemblyTitle("Doentis.Mett2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.3.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.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 ExampleEnemy { public class KutscheAI : EnemyAI { private enum State { Driving } public override void Start() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) ((EnemyAI)this).Start(); base.agent.speed = 1f; base.currentBehaviourStateIndex = 0; ((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null); Plugin.Logger.LogInfo((object)"DIE KUTSCHE!!!!"); } public override void DoAIInterval() { ((EnemyAI)this).DoAIInterval(); int currentBehaviourStateIndex = base.currentBehaviourStateIndex; } public override void OnCollideWithPlayer(Collider other) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false); if ((Object)(object)val != (Object)null) { val.DamagePlayer(2000, true, true, (CauseOfDeath)0, 0, false, default(Vector3)); } } protected override void __initializeVariables() { ((EnemyAI)this).__initializeVariables(); } protected internal override string __getTypeName() { return "KutscheAI"; } } internal class MarlonAI : EnemyAI { private enum State { SearchingForPlayer, StickingInFrontOfPlayer, HeadSwingAttackInProgress } private Random enemyRandom; private bool isDeadAnimationDone; private Vector3 positionRandomness; private Vector3 StalkPos; private float timeSinceHittingLocalPlayer; private float timeSinceNewRandPos; public Transform turnCompass; public Transform attackArea; public override void Start() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) ((EnemyAI)this).Start(); timeSinceHittingLocalPlayer = 0f; timeSinceNewRandPos = 0f; positionRandomness = new Vector3(0f, 0f, 0f); enemyRandom = new Random(StartOfRound.Instance.randomMapSeed + base.thisEnemyIndex); isDeadAnimationDone = false; base.currentBehaviourStateIndex = 0; ((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null); } public override void Update() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) ((EnemyAI)this).Update(); Animator creatureAnimator = base.creatureAnimator; Vector3 velocity = base.agent.velocity; creatureAnimator.SetBool("IsRunning", ((Vector3)(ref velocity)).magnitude > 0.1f); if (base.isEnemyDead) { base.creatureAnimator.SetInteger("Health", 0); if (!isDeadAnimationDone) { isDeadAnimationDone = true; base.creatureVoice.Stop(); base.creatureVoice.PlayOneShot(base.dieSFX); } } else { timeSinceHittingLocalPlayer += Time.deltaTime; timeSinceNewRandPos += Time.deltaTime; if (base.stunNormalizedTimer > 0f) { base.agent.speed = 0f; } } } [Conditional("DEBUG")] private void LogIfDebugBuild(string text) { Plugin.Logger.LogInfo((object)text); } public override void DoAIInterval() { //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_008d: 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) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) ((EnemyAI)this).DoAIInterval(); if (base.isEnemyDead || StartOfRound.Instance.allPlayersDead) { return; } switch (base.currentBehaviourStateIndex) { case 0: base.agent.speed = 3f; if (FoundClosestPlayerInRange(25f, 3f)) { ((EnemyAI)this).StopSearch(base.currentSearch, true); ((EnemyAI)this).SwitchToBehaviourClientRpc(1); } break; case 1: base.agent.speed = 5f; if (!TargetClosestPlayerInAnyCase() || (Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) > 20f && !((EnemyAI)this).CheckLineOfSightForPosition(((Component)base.targetPlayer).transform.position, 45f, 60, -1f, (Transform)null))) { ((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null); ((EnemyAI)this).SwitchToBehaviourClientRpc(0); } else { StickingInFrontOfPlayer(); } break; case 2: break; } } private bool FoundClosestPlayerInRange(float range, float senseRange) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) ((EnemyAI)this).TargetClosestPlayer(1.5f, true, 70f); if ((Object)(object)base.targetPlayer == (Object)null) { ((EnemyAI)this).TargetClosestPlayer(1.5f, false, 70f); range = senseRange; } if ((Object)(object)base.targetPlayer != (Object)null) { return Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) < range; } return false; } private bool TargetClosestPlayerInAnyCase() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: 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_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)base.targetPlayer == (Object)null) && ((NetworkBehaviour)this).IsOwner && timeSinceNewRandPos > 0.7f) { timeSinceNewRandPos = 0f; if (enemyRandom.Next(0, 5) == 0) { ((MonoBehaviour)this).StartCoroutine(SwingAttack()); ((EnemyAI)this).SwitchToBehaviourClientRpc(0); } else { StalkPos = ((Component)base.targetPlayer).transform.position; } ((EnemyAI)this).SetDestinationToPosition(StalkPos, false); } } private IEnumerator SwingAttack() { ((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) { DoAnimationClientRpc("Attack"); yield return (object)new WaitForSeconds(0.35f); SwingAttackHitClientRpc(); yield return (object)new WaitForSeconds(3.35f); if (base.currentBehaviourStateIndex == 2) { ((EnemyAI)this).SwitchToBehaviourClientRpc(1); } } } public override void OnCollideWithPlayer(Collider other) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) if (!(timeSinceHittingLocalPlayer < 1f)) { PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false); if ((Object)(object)val != (Object)null) { timeSinceHittingLocalPlayer = 0f; DoAnimationClientRpc("Attack"); val.DamagePlayer(20, true, true, (CauseOfDeath)0, 0, false, default(Vector3)); } } } public override void HitEnemy(int force = 1, PlayerControllerB? playerWhoHit = null, bool playHitSFX = false, int hitID = -1) { ((EnemyAI)this).HitEnemy(force, playerWhoHit, playHitSFX, hitID); if (!base.isEnemyDead) { base.enemyHP -= force; if (((NetworkBehaviour)this).IsOwner && base.enemyHP <= 0 && !base.isEnemyDead) { ((MonoBehaviour)this).StopCoroutine(SwingAttack()); ((MonoBehaviour)this).StopCoroutine(base.searchCoroutine); ((EnemyAI)this).KillEnemyOnOwnerClient(false); } } } [ClientRpc] public void DoAnimationClientRpc(string animationName) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: 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) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager == null || !networkManager.IsListening) { return; } if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost)) { ClientRpcParams val = default(ClientRpcParams); FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3960776833u, val, (RpcDelivery)0); bool flag = animationName != null; ((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives)); if (flag) { ((FastBufferWriter)(ref val2)).WriteValueSafe(animationName, false); } ((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3960776833u, val, (RpcDelivery)0); } if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost)) { base.creatureAnimator.SetTrigger(animationName); } } [ClientRpc] public void SwingAttackHitClientRpc() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: 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_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager == null || !networkManager.IsListening) { return; } if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost)) { ClientRpcParams val = default(ClientRpcParams); FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3517320282u, val, (RpcDelivery)0); ((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3517320282u, val, (RpcDelivery)0); } if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost)) { return; } int num = 8; Collider[] array = Physics.OverlapBox(attackArea.position, attackArea.localScale, Quaternion.identity, num); if (array.Length == 0) { return; } Collider[] array2 = array; foreach (Collider val3 in array2) { PlayerControllerB val4 = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(val3, false, false); if ((Object)(object)val4 != (Object)null) { timeSinceHittingLocalPlayer = 0f; val4.DamagePlayer(40, true, true, (CauseOfDeath)0, 0, false, default(Vector3)); } } } protected override void __initializeVariables() { ((EnemyAI)this).__initializeVariables(); } [RuntimeInitializeOnLoadMethod] internal static void InitializeRPCS_MarlonAI() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown NetworkManager.__rpc_func_table.Add(3960776833u, new RpcReceiveHandler(__rpc_handler_3960776833)); NetworkManager.__rpc_func_table.Add(3517320282u, new RpcReceiveHandler(__rpc_handler_3517320282)); } private static void __rpc_handler_3960776833(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams) { //IL_002f: 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_0061: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { bool flag = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives)); string animationName = null; if (flag) { ((FastBufferReader)(ref reader)).ReadValueSafe(ref animationName, false); } target.__rpc_exec_stage = (__RpcExecStage)2; ((MarlonAI)(object)target).DoAnimationClientRpc(animationName); target.__rpc_exec_stage = (__RpcExecStage)0; } } private static void __rpc_handler_3517320282(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams) { //IL_0029: 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) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { target.__rpc_exec_stage = (__RpcExecStage)2; ((MarlonAI)(object)target).SwingAttackHitClientRpc(); target.__rpc_exec_stage = (__RpcExecStage)0; } } protected internal override string __getTypeName() { return "MarlonAI"; } } [BepInPlugin("Doentis.Mett2", "Mett2", "1.0.3")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { 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)this).Config); InitializeNetworkBehaviours(); string path = "mett2assets"; 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>("Marlon"); EnemyType val2 = ModAssets.LoadAsset<EnemyType>("Kutsche"); Item val3 = ModAssets.LoadAsset<Item>("MarlonScrap"); TerminalNode val4 = ModAssets.LoadAsset<TerminalNode>("iTerminalNode"); NetworkPrefabs.RegisterNetworkPrefab(val.enemyPrefab); NetworkPrefabs.RegisterNetworkPrefab(val2.enemyPrefab); NetworkPrefabs.RegisterNetworkPrefab(val3.spawnPrefab); Enemies.RegisterEnemy(val, BoundConfig.SpawnWeight.Value, (LevelTypes)(-1), (TerminalNode)null, (TerminalKeyword)null); Enemies.RegisterEnemy(val2, BoundConfig.SpawnWeight.Value, (LevelTypes)(-1), (TerminalNode)null, (TerminalKeyword)null); Items.RegisterShopItem(val3, (TerminalNode)null, (TerminalNode)null, val4, 600); Logger.LogInfo((object)"Plugin Doentis.Mett2 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); } } } } } public static class PluginInfo { public const string PLUGIN_GUID = "Doentis.Mett2"; public const string PLUGIN_NAME = "Mett2"; public const string PLUGIN_VERSION = "1.0.3"; } } namespace ExampleEnemy.Configuration { public class PluginConfig { public ConfigEntry<int> SpawnWeight; public PluginConfig(ConfigFile cfg) { SpawnWeight = cfg.Bind<int>("General", "Spawn weight", 20, "The spawn chance weight for ExampleEnemy, relative to other existing enemies.\nGoes up from 0, lower is more rare, 100 and up is very common."); ClearUnusedEntries(cfg); } private void ClearUnusedEntries(ConfigFile cfg) { PropertyInfo property = ((object)cfg).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic); Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(cfg, null); dictionary.Clear(); cfg.Save(); } } } namespace Doentis.Mett2.NetcodePatcher { [AttributeUsage(AttributeTargets.Module)] internal class NetcodePatchedAssemblyAttribute : Attribute { } }