#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 ExampleEnemy.Configuration;
using Hamunii.ExampleEnemy.NetcodePatcher;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
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("Hamunii.ExampleEnemy")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ExampleEnemy")]
[assembly: AssemblyTitle("Hamunii.ExampleEnemy")]
[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.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
{
[BepInPlugin("Hamunii.ExampleEnemy", "ExampleEnemy", "1.0.0")]
[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 = "modAssets";
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>("SkagObject");
TerminalNode val2 = ModAssets.LoadAsset<TerminalNode>("Bestiary/SkagTN");
TerminalKeyword val3 = ModAssets.LoadAsset<TerminalKeyword>("SkagTK");
NetworkPrefabs.RegisterNetworkPrefab(val.enemyPrefab);
Enemies.RegisterEnemy(val, BoundConfig.SpawnWeight.Value, (LevelTypes)(-1), val2, val3);
Logger.LogInfo((object)"Plugin Hamunii.ExampleEnemy 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 SkagAI : EnemyAI
{
private enum State
{
SearchingForPlayer,
WaitingBeforeChase,
ChasingPlayer,
Attack
}
public Transform turnCompass = null;
private Vector3 StalkPos;
private bool isDeadAnimationDone;
public bool asAttacked = false;
public bool waitUnique = false;
[Conditional("DEBUG")]
private void LogIfDebugBuild(string text)
{
Plugin.Logger.LogInfo((object)"===========");
Plugin.Logger.LogInfo((object)text);
Plugin.Logger.LogInfo((object)"===========");
}
public override void Start()
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
((EnemyAI)this).Start();
LogIfDebugBuild("Example Enemy Spawned");
base.agent.stoppingDistance = 4f;
isDeadAnimationDone = false;
asAttacked = false;
waitUnique = false;
base.currentBehaviourStateIndex = 0;
((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
}
public override void Update()
{
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
((EnemyAI)this).Update();
if (base.isEnemyDead)
{
if (!isDeadAnimationDone)
{
LogIfDebugBuild("Stopping enemy voice with janky code.");
isDeadAnimationDone = true;
base.creatureVoice.Stop();
base.creatureVoice.PlayOneShot(base.dieSFX);
}
return;
}
int currentBehaviourStateIndex = base.currentBehaviourStateIndex;
if ((Object)(object)base.targetPlayer != (Object)null && (currentBehaviourStateIndex == 2 || currentBehaviourStateIndex == 3 || currentBehaviourStateIndex == 1))
{
turnCompass.LookAt(((Component)base.targetPlayer.gameplayCamera).transform.position);
((Component)this).transform.rotation = Quaternion.Lerp(((Component)this).transform.rotation, Quaternion.Euler(new Vector3(0f, turnCompass.eulerAngles.y, 0f)), 4f * Time.deltaTime);
}
if (base.stunNormalizedTimer > 0f)
{
base.agent.speed = 0f;
}
}
public override void DoAIInterval()
{
//IL_0256: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
((EnemyAI)this).DoAIInterval();
if (base.isEnemyDead || StartOfRound.Instance.allPlayersDead)
{
return;
}
LogIfDebugBuild(base.currentBehaviourStateIndex.ToString());
switch (base.currentBehaviourStateIndex)
{
case 0:
base.agent.speed = 3.5f;
LogIfDebugBuild("il cherche la en fait");
asAttacked = false;
waitUnique = false;
base.agent.isStopped = false;
base.creatureSFX.Stop();
DoAnimationClientRpc("Run");
if (FoundClosestPlayerInRange(15f, 3f))
{
LogIfDebugBuild("Start Target Player");
((EnemyAI)this).StopSearch(base.currentSearch, true);
((EnemyAI)this).SwitchToBehaviourClientRpc(1);
}
break;
case 1:
DoAnimationClientRpc("Idle");
LogIfDebugBuild("Waiting before chase");
base.creatureVoice.Stop();
base.agent.isStopped = true;
if (!waitUnique)
{
((MonoBehaviour)this).StartCoroutine(WaitAndSwitchState(10f, State.ChasingPlayer));
waitUnique = true;
}
break;
case 2:
if ((Object)(object)base.targetPlayer != (Object)null)
{
float num = 50f;
float num2 = 3f;
DoAnimationClientRpc("Run");
base.agent.isStopped = false;
base.agent.speed = 10f;
if (Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) < num2)
{
((EnemyAI)this).SetDestinationToPosition(((Component)base.targetPlayer).transform.position, false);
((EnemyAI)this).SwitchToBehaviourClientRpc(3);
}
else if (Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) > num)
{
((EnemyAI)this).SwitchToBehaviourClientRpc(0);
}
else
{
((EnemyAI)this).SetDestinationToPosition(((Component)base.targetPlayer).transform.position, false);
}
}
else
{
((EnemyAI)this).SwitchToBehaviourClientRpc(0);
}
break;
case 3:
base.targetPlayer.DamagePlayer(95, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
DoAnimationClientRpc("Attack");
base.creatureSFX.Stop();
((EnemyAI)this).SwitchToBehaviourClientRpc(0);
break;
default:
LogIfDebugBuild("This Behavior State doesn't exist!");
break;
}
}
private IEnumerator WaitAndSwitchState(float waitTime, State newState)
{
yield return (object)new WaitForSeconds(waitTime);
((EnemyAI)this).SwitchToBehaviourClientRpc((int)newState);
}
private bool FoundClosestPlayerInRange(float range, float senseRange)
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: 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;
}
return (Object)(object)base.targetPlayer != (Object)null && Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) < range;
}
[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(409254728u, 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, 409254728u, val, (RpcDelivery)0);
}
if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
LogIfDebugBuild("Playing animation: " + animationName);
base.creatureAnimator.SetTrigger(animationName);
}
}
protected override void __initializeVariables()
{
((EnemyAI)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_SkagAI()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(409254728u, new RpcReceiveHandler(__rpc_handler_409254728));
}
private static void __rpc_handler_409254728(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;
((SkagAI)(object)target).DoAnimationClientRpc(animationName);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
protected internal override string __getTypeName()
{
return "SkagAI";
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "Hamunii.ExampleEnemy";
public const string PLUGIN_NAME = "ExampleEnemy";
public const string PLUGIN_VERSION = "1.0.0";
}
}
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 Hamunii.ExampleEnemy.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}