Decompiled source of StarlancerMoons v2.4.0

StarlancerMoons.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLevelLoader;
using Microsoft.CodeAnalysis;
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("StarlancerMoons")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3072f031f84581ef19eff40c10031a44487d0775")]
[assembly: AssemblyProduct("StarlancerMoons")]
[assembly: AssemblyTitle("StarlancerMoons")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 StarlancerMoons
{
	[BepInPlugin("AudioKnight.StarlancerMoons", "Starlancer Moons", "2.2.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class StarlancerMoonsBase : BaseUnityPlugin
	{
		private const string modGUID = "AudioKnight.StarlancerMoons";

		private const string modName = "Starlancer Moons";

		private const string modVersion = "2.2.1";

		private readonly Harmony harmony = new Harmony("AudioKnight.StarlancerMoons");

		public static StarlancerMoonsBase Instance;

		internal static ManualLogSource logger;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = ((BaseUnityPlugin)this).Logger;
			logger.LogInfo((object)"StarlancerMoons scripts loaded.");
			harmony.PatchAll(typeof(StarlancerMoonsBase));
			harmony.PatchAll(typeof(TerminalManagerPatch));
		}
	}
	public class DamageTrigger : MonoBehaviour
	{
		public float cooldownTime;

		public int damageAmount;

		public CauseOfDeath causeOfDeath;

		private float timeSincePlayerDamaged = 0f;

		private void OnTriggerStay(Collider other)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if (((Component)other).gameObject.CompareTag("Player"))
			{
				if (timeSincePlayerDamaged < cooldownTime)
				{
					timeSincePlayerDamaged += Time.deltaTime;
				}
				else if ((Object)(object)component != (Object)null && !component.isInsideFactory)
				{
					timeSincePlayerDamaged = 0f;
					component.DamagePlayer(damageAmount, true, true, causeOfDeath, 0, false, default(Vector3));
				}
			}
		}
	}
	public class lookAtPlayerXZ : MonoBehaviour
	{
		private Vector3 playerPositionXZ;

		private AudioListener target = StartOfRound.Instance.audioListener;

		private void Update()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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)
			//IL_0051: 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)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)StartOfRound.Instance.audioListener != (Object)null)
			{
				playerPositionXZ = new Vector3(((Component)target).transform.position.x, ((Component)this).transform.position.y, ((Component)target).transform.position.z);
				((Component)this).transform.LookAt(playerPositionXZ);
			}
		}
	}
	[HarmonyPatch(typeof(TerminalManager))]
	internal static class TerminalManagerPatch
	{
		private static readonly Dictionary<string, string> KeywordReplacements = new Dictionary<string, string> { { "starlancerzero", "anomaly" } };

		private static void EditTerminalKeyword(ExtendedLevel level, TerminalKeyword keyword)
		{
			if (KeywordReplacements.TryGetValue(keyword.word, out string value))
			{
				keyword.word = value;
			}
		}

		[HarmonyTranspiler]
		[HarmonyPatch("CreateLevelTerminalData")]
		private static IEnumerable<CodeInstruction> DebugLogging(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[3]
			{
				new CodeMatch((OpCode?)OpCodes.Ldloc_0, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldsfld, (object)AccessTools.Field(typeof(TerminalManager), "routeKeyword"), (string)null),
				new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(TerminalKeyword), "defaultVerb"), (string)null)
			}).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldloc_0, (object)null),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(TerminalManagerPatch), "EditTerminalKeyword", (Type[])null, (Type[])null))
			}).InstructionEnumeration();
		}
	}
}

WanderingCreature.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[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("WanderingCreature")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Test")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1")]
[assembly: AssemblyProduct("WanderingCreature")]
[assembly: AssemblyTitle("WanderingCreature")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[BepInPlugin("WanderingCreature", "Wandering Creature", "1.2.1")]
public class WanderingCreature : BaseUnityPlugin
{
	private void Awake()
	{
		Debug.Log((object)"WanderingCreaturePlugin loaded");
	}
}
public class WanderingCreatureController : NetworkBehaviour
{
	[Header("Movement")]
	[Tooltip("The maximum distance from the creature's current position within which it can wander.")]
	public float wanderRadius = 10f;

	[Tooltip("The duration the creature waits at its destination before selecting a new destination to wander towards.")]
	public float waitTime = 3f;

	[Tooltip("If enabled, the wait time becomes random within the range [0, Wait Time].")]
	public bool randomTime;

	[Tooltip("Toggle whether the creature is allowed to wander or not.")]
	public bool wanderEnabled = true;

	[Tooltip("When enabled, the creature will only wander around its spawn point within a radius defined by the Wander Radius. If disabled, the creature can wander from any point within the Wander Radius.")]
	public bool anchoredWandering = true;

	[Header("Audio")]
	public AudioSource ambientAudioSource;

	[Tooltip("An array of audio clips that can be played randomly at intervals while the creature is wandering.")]
	public AudioClip[] ambientAudioClips;

	[Tooltip("The minimum interval between playing ambient audio clips.")]
	public float minAmbientAudioInterval = 3f;

	[Tooltip("The maximum interval between playing ambient audio clips.")]
	public float maxAmbientAudioInterval = 7f;

	[Tooltip("The volume for ambient audio.")]
	[Range(0f, 2f)]
	public float ambientAudioVolume = 1f;

	[Space]
	public AudioSource walkingAudioSource;

	[Tooltip("An array of audio clips that can be played randomly at intervals while the creature is moving.")]
	public AudioClip[] walkingAudioClips;

	[Tooltip("The interval between playing walking audio clips.")]
	public float walkingAudioInterval = 0.5f;

	[Tooltip("The volume for walking audio.")]
	[Range(0f, 2f)]
	public float walkingAudioVolume = 1f;

	[Header("Rotation")]
	[Tooltip("If enabled, the creature will follow the surface normal underneath it.")]
	public bool followSurface;

	[Tooltip("The distance to cast the ray to detect the surface normal.")]
	public float surfaceNormalRaycastDistance = 2f;

	private NavMeshAgent agent;

	private bool isMoving;

	private bool startMovingSignal;

	private float waitTimer;

	private float ambientAudioTimer;

	private float walkingAudioTimer;

	private int currentAmbientClipIndex;

	private Vector3 startPosition;

	private float lastSyncedAmbientAudioTimer;

	private float syncedWaitTimer;

	private void Start()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		startPosition = ((Component)this).transform.position;
		agent = ((Component)this).GetComponent<NavMeshAgent>();
		if (((NetworkBehaviour)this).IsServer)
		{
			GenerateDestination();
			startMovingSignal = true;
		}
		if ((Object)(object)ambientAudioSource == (Object)null || (Object)(object)walkingAudioSource == (Object)null)
		{
			Debug.LogError((object)"WaderingCreatureController: One or both AudioSource components are not assigned!");
			return;
		}
		ambientAudioSource.volume = ambientAudioVolume;
		walkingAudioSource.volume = walkingAudioVolume;
	}

	private void Update()
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		if (!wanderEnabled)
		{
			return;
		}
		if (startMovingSignal && !isMoving && waitTimer <= 0f)
		{
			GenerateDestinationServerRpc();
			startMovingSignal = false;
		}
		if (isMoving)
		{
			if (!agent.pathPending && agent.remainingDistance <= agent.stoppingDistance)
			{
				if (agent.hasPath)
				{
					Vector3 velocity = agent.velocity;
					if (((Vector3)(ref velocity)).sqrMagnitude != 0f)
					{
						goto IL_010c;
					}
				}
				isMoving = false;
				syncedWaitTimer = waitTimer;
				WaitTimerSyncServerRpc(waitTimer);
				if (randomTime)
				{
					waitTimer = Random.Range(0f, waitTime);
				}
				else
				{
					waitTimer = waitTime;
				}
			}
		}
		else if (waitTimer > 0f)
		{
			waitTimer -= Time.deltaTime;
		}
		else if (((NetworkBehaviour)this).IsServer)
		{
			GenerateDestinationServerRpc();
		}
		goto IL_010c;
		IL_010c:
		if (ambientAudioClips != null && ambientAudioClips.Length != 0)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				ambientAudioTimer -= Time.deltaTime;
				if (ambientAudioTimer <= 0f)
				{
					ambientAudioTimer = Random.Range(minAmbientAudioInterval, maxAmbientAudioInterval);
					lastSyncedAmbientAudioTimer = ambientAudioTimer;
					AmbientAudioTimerSyncServerRpc(ambientAudioTimer);
				}
			}
			else
			{
				ambientAudioTimer = lastSyncedAmbientAudioTimer;
			}
			if (ambientAudioTimer <= 0f)
			{
				SelectAmbientAudioClipServerRpc();
			}
		}
		if (isMoving && walkingAudioClips != null)
		{
			walkingAudioTimer -= Time.deltaTime;
			if (walkingAudioTimer <= 0f)
			{
				int num = Random.Range(0, walkingAudioClips.Length);
				walkingAudioSource.clip = walkingAudioClips[num];
				walkingAudioSource.Play();
				walkingAudioTimer = walkingAudioInterval;
			}
		}
		if (followSurface)
		{
			RotateToFollowSurfaceNormal();
		}
	}

	private void GenerateDestination()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: 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)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = Random.insideUnitSphere * wanderRadius;
		if (anchoredWandering)
		{
			val += startPosition;
		}
		NavMeshHit val2 = default(NavMeshHit);
		NavMesh.SamplePosition(val, ref val2, wanderRadius, -1);
		Vector3 position = ((NavMeshHit)(ref val2)).position;
		agent.SetDestination(position);
		isMoving = true;
	}

	private void RotateToFollowSurfaceNormal()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: 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)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		RaycastHit val = default(RaycastHit);
		if (Physics.Raycast(((Component)this).transform.position, Vector3.down, ref val, surfaceNormalRaycastDistance))
		{
			Vector3 normal = ((RaycastHit)(ref val)).normal;
			Quaternion rotation = Quaternion.FromToRotation(((Component)this).transform.up, normal) * ((Component)this).transform.rotation;
			((Component)this).transform.rotation = rotation;
		}
	}

	private void OnDrawGizmosSelected()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		Gizmos.color = Color.green;
		Gizmos.DrawWireSphere(((Component)this).transform.position, wanderRadius);
	}

	[ServerRpc(RequireOwnership = false)]
	private void GenerateDestinationServerRpc()
	{
		GenerateDestination();
		GenerateDestinationClientRpc();
	}

	[ClientRpc]
	private void GenerateDestinationClientRpc()
	{
		isMoving = true;
	}

	[ServerRpc(RequireOwnership = false)]
	private void SelectAmbientAudioClipServerRpc()
	{
		currentAmbientClipIndex = Random.Range(0, ambientAudioClips.Length);
		SelectAmbientAudioClipClientRpc(currentAmbientClipIndex);
	}

	[ClientRpc]
	private void SelectAmbientAudioClipClientRpc(int clipIndex)
	{
		if (ambientAudioClips != null && ambientAudioClips.Length != 0)
		{
			currentAmbientClipIndex = clipIndex;
			ambientAudioSource.clip = ambientAudioClips[currentAmbientClipIndex];
			ambientAudioSource.Play();
		}
	}

	[ServerRpc(RequireOwnership = false)]
	private void AmbientAudioTimerSyncServerRpc(float timerValue)
	{
		lastSyncedAmbientAudioTimer = timerValue;
		AmbientAudioTimerSyncClientRpc(timerValue);
	}

	[ClientRpc]
	private void AmbientAudioTimerSyncClientRpc(float timerValue)
	{
		lastSyncedAmbientAudioTimer = timerValue;
	}

	[ServerRpc(RequireOwnership = false)]
	private void WaitTimerSyncServerRpc(float timerValue)
	{
		syncedWaitTimer = timerValue;
		WaitTimerSyncClientRpc(timerValue);
	}

	[ClientRpc]
	private void WaitTimerSyncClientRpc(float timerValue)
	{
		syncedWaitTimer = timerValue;
	}
}