Decompiled source of JesterEditedFree v1.2.5

JesterFree.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LCSoundTool;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("JesterFree")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JesterFree")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("E5A9D456-B06D-4FBC-A40E-190441538DF6")]
[assembly: AssemblyFileVersion("2.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("2.0.0.0")]
namespace JesterFree;

[BepInPlugin("AriDev.JesterFree", "Jester Free", "2.0.0")]
public class JesterFreeBase : BaseUnityPlugin
{
	public static ManualLogSource Log;

	public static AudioClip Intro;

	public static AudioClip Solo1;

	public static AudioClip Solo2;

	public static AudioClip Solo3;

	public static ConfigEntry<bool> IntroEnabled;

	public static ConfigEntry<bool> SoloEnabled;

	public static ConfigEntry<int> IntroVolume;

	public static ConfigEntry<int> SoloVolume;

	public static string SoundPath;

	private void Awake()
	{
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		SoundPath = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
		IntroEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Sound", "EnableIntro", true, "Intro");
		IntroVolume = ((BaseUnityPlugin)this).Config.Bind<int>("Sound", "IntroVolume", 50, "Vol");
		SoloEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Sound", "EnableSolo", true, "Solo");
		SoloVolume = ((BaseUnityPlugin)this).Config.Bind<int>("Sound", "SoloVolume", 100, "Vol");
		Log.LogInfo((object)"[JESTER] Mod pret. Les sons seront charges au premier spawn.");
		new Harmony("AriDev.JesterFree").PatchAll(typeof(JesterAiPatch));
	}

	public static void LoadSounds()
	{
		Log.LogInfo((object)("[JESTER] Chargement des fichiers .ogg depuis : " + SoundPath));
		try
		{
			Intro = SoundTool.GetAudioClip(SoundPath, "intro.ogg");
			Solo1 = SoundTool.GetAudioClip(SoundPath, "solo_01.ogg");
			Solo2 = SoundTool.GetAudioClip(SoundPath, "solo_02.ogg");
			Solo3 = SoundTool.GetAudioClip(SoundPath, "solo_03.ogg");
			Log.LogInfo((object)"[JESTER] Chargement SoundTool termine.");
		}
		catch (Exception ex)
		{
			Log.LogError((object)("[JESTER] Crash lors du chargement : " + ex.Message));
		}
	}
}
[HarmonyPatch(typeof(JesterAI))]
public static class JesterAiPatch
{
	[HarmonyPatch("Start")]
	[HarmonyPrefix]
	public static void JesterFreePatch(ref AudioClip ___popGoesTheWeaselTheme, ref AudioClip ___screamingSFX, ref AudioSource ___farAudio, ref AudioSource ___creatureVoice)
	{
		JesterFreeBase.Log.LogInfo((object)"[JESTER] --- DEBUT DU PATCH (SPAWN) ---");
		if ((Object)(object)JesterFreeBase.Intro == (Object)null)
		{
			JesterFreeBase.LoadSounds();
		}
		if (JesterFreeBase.IntroEnabled.Value && (Object)(object)JesterFreeBase.Intro != (Object)null)
		{
			___popGoesTheWeaselTheme = JesterFreeBase.Intro;
			if ((Object)(object)___farAudio != (Object)null)
			{
				___farAudio.volume = (float)JesterFreeBase.IntroVolume.Value / 100f;
			}
			JesterFreeBase.Log.LogInfo((object)"[JESTER] Intro appliquee.");
		}
		if (!JesterFreeBase.SoloEnabled.Value)
		{
			return;
		}
		int seed = 0;
		if ((Object)(object)StartOfRound.Instance != (Object)null)
		{
			seed = StartOfRound.Instance.randomMapSeed;
		}
		int num = new Random(seed).Next(0, 3);
		AudioClip val = null;
		val = (AudioClip)(num switch
		{
			0 => JesterFreeBase.Solo1, 
			1 => JesterFreeBase.Solo2, 
			_ => JesterFreeBase.Solo3, 
		});
		if ((Object)(object)val != (Object)null)
		{
			___screamingSFX = val;
			if ((Object)(object)___creatureVoice != (Object)null)
			{
				___creatureVoice.volume = (float)JesterFreeBase.SoloVolume.Value / 100f;
			}
			JesterFreeBase.Log.LogInfo((object)("[JESTER] Solo #" + (num + 1) + " applique (Seed: " + seed + ")"));
		}
		else
		{
			JesterFreeBase.Log.LogError((object)"[JESTER] Erreur : Le son choisi est toujours NULL !");
		}
	}
}