Decompiled source of Darklink3DModel v0.1.0

DarkLinkOOT3DOne.dll

Decompiled 12 hours ago
using System;
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 HarmonyLib;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("DarkLinkOOT3DOne")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DarkLinkOOT3DOne")]
[assembly: AssemblyTitle("DarkLinkOOT3DOne")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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 ModelReplacement
{
	internal static class DarkLinkSettings
	{
		internal static readonly ManualLogSource Log;

		private static readonly ConfigEntry<bool> enableDeathSound;

		private static readonly ConfigEntry<float> deathVolume;

		private static readonly ConfigEntry<bool> enableActionSounds;

		private static readonly ConfigEntry<float> actionVolume;

		internal static bool DeathSoundEnabled => enableDeathSound.Value;

		internal static float DeathVolume => deathVolume.Value;

		internal static bool ActionSoundsEnabled => enableActionSounds.Value;

		internal static float ActionVolume => actionVolume.Value;

		static DarkLinkSettings()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			Log = Logger.CreateLogSource("DarkLink");
			ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "DarkLink.Settings.cfg"), true);
			enableDeathSound = val.Bind<bool>("Dark Link", "Enable death sound", true, "Turns the death scream on/off.");
			deathVolume = val.Bind<float>("Dark Link", "Death sound volume", 1f, new ConfigDescription("Volume of the death scream (0 to 1).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			enableActionSounds = val.Bind<bool>("Dark Link", "Enable action sounds", true, "Turns the sounds for picking up an item, dropping an item and getting hit on/off.");
			actionVolume = val.Bind<float>("Dark Link", "Action sounds volume", 1f, new ConfigDescription("Volume of the pickup/drop/hit sounds (0 to 1).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		}
	}
	public class MRDARKLINKMODEL : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "DarkLinkModel";
			GameObject val = Assets.MainAssetBundle.LoadAsset<GameObject>(text);
			if ((Object)(object)val != (Object)null && (DarkLinkSettings.DeathSoundEnabled || DarkLinkSettings.ActionSoundsEnabled) && (Object)(object)val.GetComponent<DarkLinkController>() == (Object)null)
			{
				val.AddComponent<DarkLinkController>();
			}
			return val;
		}

		protected override void OnEmoteStart(int emoteId)
		{
			GetController(base.replacementModel);
		}

		protected override void OnEmoteEnd()
		{
			GetController(base.replacementModel);
		}

		protected override void OnDeath()
		{
			if (!((Object)(object)base.replacementDeadBody == (Object)null))
			{
				DarkLinkController darkLinkController = GetController(base.replacementDeadBody);
				if ((Object)(object)darkLinkController == (Object)null)
				{
					darkLinkController = base.replacementDeadBody.AddComponent<DarkLinkController>();
				}
				darkLinkController.SetDead();
			}
		}

		private DarkLinkController GetController(GameObject obj)
		{
			if ((Object)(object)obj == (Object)null)
			{
				return null;
			}
			DarkLinkController componentInChildren = obj.GetComponentInChildren<DarkLinkController>(true);
			if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.Player == (Object)null)
			{
				componentInChildren.Player = ((Component)this).GetComponent<PlayerControllerB>();
			}
			return componentInChildren;
		}
	}
	public class DarkLinkController : MonoBehaviour
	{
		private const string DeathClipName = "Dark_Link_Death";

		private const string PickupClipName = "Dark_Link_Pickup";

		private const string DropClipName = "Dark_Link_Drop";

		private const string HitClipName = "Dark_Link_Hit";

		public PlayerControllerB Player;

		private AudioSource actionSource;

		private bool isDead;

		private bool deathSoundPlayed;

		private int lastHealth = -1;

		private int lastItemCount = -1;

		private float lastHitTime;

		private static readonly Dictionary<string, AudioClip> clipCache = new Dictionary<string, AudioClip>();

		private void Start()
		{
			if ((Object)(object)Player == (Object)null)
			{
				Player = ((Component)this).GetComponentInParent<PlayerControllerB>(true);
			}
		}

		private void Update()
		{
			if (!isDead && !((Object)(object)Player == (Object)null))
			{
				PollActions();
			}
		}

		public void SetDead()
		{
			isDead = true;
			PlayDeathSound();
		}

		private void PlayDeathSound()
		{
			if (!deathSoundPlayed && DarkLinkSettings.DeathSoundEnabled)
			{
				deathSoundPlayed = true;
				AudioClip clip = GetClip("Dark_Link_Death", warn: true);
				if (!((Object)(object)clip == (Object)null))
				{
					AudioSource val = ((Component)this).gameObject.AddComponent<AudioSource>();
					val.clip = clip;
					val.volume = DarkLinkSettings.DeathVolume;
					val.spatialBlend = 1f;
					val.rolloffMode = (AudioRolloffMode)1;
					val.minDistance = 4f;
					val.maxDistance = 45f;
					val.playOnAwake = false;
					val.Play();
					Object.Destroy((Object)(object)val, clip.length + 0.5f);
				}
			}
		}

		private static AudioClip GetClip(string name, bool warn)
		{
			if (clipCache.TryGetValue(name, out AudioClip value))
			{
				return value;
			}
			AudioClip val = Assets.MainAssetBundle.LoadAsset<AudioClip>(name);
			if ((Object)(object)val == (Object)null && warn)
			{
				DarkLinkSettings.Log.LogWarning((object)("AudioClip '" + name + "' was not found in the AssetBundle."));
			}
			clipCache[name] = val;
			return val;
		}

		private void PlayAction(string baseName, int expected = 1)
		{
			AudioClip[] array = (AudioClip[])(object)new AudioClip[3];
			int num = 0;
			AudioClip clip = GetClip(baseName, warn: true);
			if ((Object)(object)clip != (Object)null)
			{
				array[num++] = clip;
			}
			clip = GetClip(baseName + "2", expected >= 2);
			if ((Object)(object)clip != (Object)null)
			{
				array[num++] = clip;
			}
			clip = GetClip(baseName + "3", expected >= 3);
			if ((Object)(object)clip != (Object)null)
			{
				array[num++] = clip;
			}
			if (num != 0)
			{
				if ((Object)(object)actionSource == (Object)null)
				{
					actionSource = ((Component)this).gameObject.AddComponent<AudioSource>();
					actionSource.playOnAwake = false;
					actionSource.spatialBlend = 1f;
					actionSource.rolloffMode = (AudioRolloffMode)1;
					actionSource.minDistance = 4f;
					actionSource.maxDistance = 45f;
				}
				actionSource.PlayOneShot(array[Random.Range(0, num)], DarkLinkSettings.ActionVolume);
			}
		}

		private void PollActions()
		{
			if (!DarkLinkSettings.ActionSoundsEnabled || Player.isPlayerDead)
			{
				return;
			}
			int health = Player.health;
			if (lastHealth >= 0 && health < lastHealth && health > 0 && Time.time - lastHitTime > 0.4f)
			{
				lastHitTime = Time.time;
				PlayAction("Dark_Link_Hit", 3);
			}
			lastHealth = health;
			int num = CountItems();
			if (lastItemCount >= 0)
			{
				if (num > lastItemCount)
				{
					PlayAction("Dark_Link_Pickup");
				}
				else if (num < lastItemCount)
				{
					PlayAction("Dark_Link_Drop");
				}
			}
			lastItemCount = num;
		}

		private int CountItems()
		{
			GrabbableObject[] itemSlots = Player.ItemSlots;
			if (itemSlots == null)
			{
				return 0;
			}
			int num = 0;
			for (int i = 0; i < itemSlots.Length; i++)
			{
				if ((Object)(object)itemSlots[i] != (Object)null)
				{
					num++;
				}
			}
			return num;
		}
	}
	[BepInPlugin("darklinkmodoot", "Darklink3DModel", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigFile config;

		public static ConfigEntry<bool> enableModelForAllSuits { get; private set; }

		public static ConfigEntry<bool> enableModelAsDefault { get; private set; }

		public static ConfigEntry<string> suitNamesToEnableModel { get; private set; }

		private static void InitConfig()
		{
			enableModelForAllSuits = config.Bind<bool>("Suits to Replace Settings", "Enable Model for all Suits", false, "Enable to model replace every suit. Set to false to specify suits");
			enableModelAsDefault = config.Bind<bool>("Suits to Replace Settings", "Enable Model as default", false, "Enable to model replace every suit that hasn't been otherwise registered.");
			suitNamesToEnableModel = config.Bind<string>("Suits to Replace Settings", "Suits to enable Model for", "darklinkmodoot", "Enter a comma separated list of suit names.(Additionally, [Green suit,Pajama suit,Hazard suit])");
		}

		private void Awake()
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			config = ((BaseUnityPlugin)this).Config;
			InitConfig();
			Assets.PopulateAssets();
			if (enableModelForAllSuits.Value)
			{
				ModelReplacementAPI.RegisterModelReplacementOverride(typeof(MRDARKLINKMODEL));
			}
			if (enableModelAsDefault.Value)
			{
				ModelReplacementAPI.RegisterModelReplacementDefault(typeof(MRDARKLINKMODEL));
			}
			string[] array = suitNamesToEnableModel.Value.Split(',');
			string[] array2 = array;
			foreach (string text in array2)
			{
				ModelReplacementAPI.RegisterSuitModelReplacement("DarkLink", typeof(MRDARKLINKMODEL));
			}
			Harmony val = new Harmony("darklinkmodoot");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin darklinkmodoot is loaded!");
		}
	}
	public static class Assets
	{
		public static string mainAssetBundleName = "darklinkootsbundle";

		public static AssetBundle MainAssetBundle = null;

		private static string GetAssemblyName()
		{
			return Assembly.GetExecutingAssembly().GetName().Name.Replace(" ", "_");
		}

		public static void PopulateAssets()
		{
			if ((Object)(object)MainAssetBundle == (Object)null)
			{
				Console.WriteLine(GetAssemblyName() + "." + mainAssetBundleName);
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetAssemblyName() + "." + mainAssetBundleName);
				MainAssetBundle = AssetBundle.LoadFromStream(stream);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}