Decompiled source of Jestlander v1.2.0

Jestlander.dll

Decompiled 8 months ago
using System;
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.Logging;
using HarmonyLib;
using LCJestlander.Patches;
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("0Harmony")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("BepInEx")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: AssemblyCompany("Jestlander")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Replaces Jester windup and scream noises with that bit from hit song Highlander by Lost Horizon.")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0")]
[assembly: AssemblyProduct("Jestlander")]
[assembly: AssemblyTitle("Jestlander")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.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;
		}
	}
}
namespace LCJestlander
{
	[BepInPlugin("raptureawaits.jestlander", "Jestlander", "1.2.0")]
	public class JestlanderBase : BaseUnityPlugin
	{
		private const string mod_guid = "raptureawaits.jestlander";

		private const string mod_name = "Jestlander";

		private const string mod_version = "1.2.0";

		internal static JestlanderBase instance;

		internal static ManualLogSource modlog;

		public static AssetBundle new_sounds;

		internal static AudioClip[] windup_asset;

		internal static AudioClip[] pop_asset;

		internal static AudioClip[] scream_asset;

		private readonly Harmony harmony = new Harmony("raptureawaits.jestlander");

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			modlog = Logger.CreateLogSource("Jestlander");
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			new_sounds = AssetBundle.LoadFromFile(Path.Combine(directoryName, "jestlander_sounds"));
			if ((Object)(object)new_sounds == (Object)null)
			{
				modlog.LogError((object)"Failed to load AssetBundle.");
				return;
			}
			windup_asset = new_sounds.LoadAssetWithSubAssets<AudioClip>("assets\\audio\\windup.wav");
			pop_asset = new_sounds.LoadAssetWithSubAssets<AudioClip>("assets\\audio\\pop.wav");
			scream_asset = new_sounds.LoadAssetWithSubAssets<AudioClip>("assets\\audio\\scream.wav");
			harmony.PatchAll(typeof(JesterAIPatch));
			modlog.LogInfo((object)"Plugin raptureawaits.jestlander is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Jestlander";

		public const string PLUGIN_NAME = "Jestlander";

		public const string PLUGIN_VERSION = "1.2.0";
	}
}
namespace LCJestlander.Patches
{
	[HarmonyPatch(typeof(JesterAI))]
	internal class JesterAIPatch
	{
		internal static ManualLogSource modlog = JestlanderBase.modlog;

		internal static float second_offset;

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void AudioPatch(ref AudioClip ___popUpSFX, ref AudioClip ___screamingSFX)
		{
			AudioClip[] pop_asset = JestlanderBase.pop_asset;
			if (pop_asset != null && pop_asset.Length != 0)
			{
				AudioClip val = pop_asset[0];
				___popUpSFX = val;
			}
			else
			{
				modlog.LogError((object)"Failed to load pop replacement audio data from extracted assets.");
			}
			AudioClip[] scream_asset = JestlanderBase.scream_asset;
			if (scream_asset != null && scream_asset.Length != 0)
			{
				AudioClip val2 = scream_asset[0];
				___screamingSFX = val2;
			}
			else
			{
				modlog.LogError((object)"Failed to load scream replacement audio data from extracted assets.");
			}
		}

		[HarmonyPatch("SetJesterInitialValues")]
		[HarmonyPostfix]
		private static void AudioPatch(ref AudioClip ___popGoesTheWeaselTheme, ref float ___popUpTimer)
		{
			AudioClip[] windup_asset = JestlanderBase.windup_asset;
			if (windup_asset != null && windup_asset.Length != 0)
			{
				AudioClip val = windup_asset[0];
				if (GameNetworkManager.Instance.isHostingGame)
				{
					modlog.LogInfo((object)"Player is host, adjusting windup clip...");
					second_offset = val.length - 5f - ___popUpTimer;
				}
				else
				{
					modlog.LogInfo((object)"Player is not host, using static windup clip.");
					second_offset = val.length - 40f;
				}
				int num = (int)(second_offset / val.length * (float)val.samples);
				int num2 = val.samples - num;
				float[] array = new float[num2 * val.channels];
				val.GetData(array, num);
				AudioClip val2 = AudioClip.Create(((Object)val).name + "_cropped", num2, val.channels, val.frequency, false);
				val2.SetData(array, 0);
				___popGoesTheWeaselTheme = val2;
			}
			else
			{
				modlog.LogError((object)"Failed to load windup replacement audio data from extracted assets.");
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}