#define DEBUG
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LooseJesterSpring.Patches;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Networking;
[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("TestAccount666.LooseJesterSpring")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("The spring that's holding the Jester shut is a little loose")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4")]
[assembly: AssemblyProduct("LooseJesterSpring")]
[assembly: AssemblyTitle("TestAccount666.LooseJesterSpring")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.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.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 LooseJesterSpring
{
public class ConfigManager
{
internal ConfigEntry<int> popChance = null;
internal ConfigEntry<int> volume = null;
internal ConfigEntry<bool> enableSound = null;
internal void Setup(ConfigFile configFile)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Expected O, but got Unknown
popChance = configFile.Bind<int>("General", "1. Pop Chance", 100, new ConfigDescription("A chance in percent that the jester will pop upon hit", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
enableSound = configFile.Bind<bool>("Sound", "1. Enable Sound", true, "If true, will play a sound upon hitting the jester (Requires LCSoundTool to be installed)");
volume = configFile.Bind<int>("Sound", "2. Volume", 100, new ConfigDescription("The volume the sound will be playing", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
}
}
internal class DependencyChecker
{
internal static bool IsSoundToolInstalled()
{
return Chainloader.PluginInfos.Values.Any((PluginInfo metadata) => metadata.Metadata.GUID.Contains("LCSoundTool"));
}
}
[BepInPlugin("TestAccount666.LooseJesterSpring", "LooseJesterSpring", "1.0.4")]
public class LooseJesterSpring : BaseUnityPlugin
{
internal static AudioClip? audioClip;
internal static ConfigManager configManager = null;
internal static Random syncedRandom = new Random();
public static LooseJesterSpring Instance { get; private set; } = null;
internal static ManualLogSource Logger { get; private set; } = null;
internal static Harmony? Harmony { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
configManager = new ConfigManager();
configManager.Setup(((BaseUnityPlugin)this).Config);
if (configManager.enableSound.Value)
{
((MonoBehaviour)this).StartCoroutine(LoadSound());
}
Patch();
Logger.LogInfo((object)"TestAccount666.LooseJesterSpring v1.0.4 has loaded!");
}
internal static void Patch()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("TestAccount666.LooseJesterSpring");
}
Logger.LogDebug((object)"Patching...");
Harmony.PatchAll(typeof(EnemyAIPatch));
Harmony.PatchAll(typeof(RoundManagerPatch));
Logger.LogDebug((object)"Finished patching!");
}
internal static void Unpatch()
{
Logger.LogDebug((object)"Unpatching...");
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Logger.LogDebug((object)"Finished unpatching!");
}
private static IEnumerator LoadSound()
{
string assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Debug.Assert(assemblyDirectory != null, "assemblyDirectory != null");
string filePath = Path.Combine(assemblyDirectory, "fool.wav");
audioClip = LoadAudioClipFromFile(new Uri(filePath), "fool.wav");
yield break;
}
private static AudioClip? LoadAudioClipFromFile(Uri filePath, string name)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Invalid comparison between Unknown and I4
UnityWebRequest val = UnityWebRequestMultimedia.GetAudioClip(filePath, (AudioType)20);
try
{
UnityWebRequestAsyncOperation val2 = val.SendWebRequest();
while (!((AsyncOperation)val2).isDone)
{
Thread.Sleep(100);
}
if ((int)val.result != 1)
{
Logger.LogError((object)("Failed to load AudioClip: " + val.error));
return null;
}
AudioClip content = DownloadHandlerAudioClip.GetContent(val);
((Object)content).name = name;
return content;
}
finally
{
((IDisposable)val)?.Dispose();
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "TestAccount666.LooseJesterSpring";
public const string PLUGIN_NAME = "LooseJesterSpring";
public const string PLUGIN_VERSION = "1.0.4";
}
}
namespace LooseJesterSpring.Patches
{
[HarmonyPatch(typeof(EnemyAI))]
public static class EnemyAIPatch
{
[HarmonyPatch("HitEnemyServerRpc")]
[HarmonyPostfix]
private static void JesterHitClientPostfix(EnemyAI __instance)
{
HandleJesterPop(__instance);
}
private static void HandleJesterPop(EnemyAI enemyAI)
{
LooseJesterSpring.Logger.LogFatal((object)("Enemy was hit: " + ((Object)enemyAI.enemyType).name));
if (enemyAI is JesterAI && ((NetworkBehaviour)enemyAI).IsHost)
{
LooseJesterSpring.Logger.LogFatal((object)"Enemy was Jester!");
int num = LooseJesterSpring.syncedRandom.Next(0, 100);
LooseJesterSpring.Logger.LogFatal((object)$"Rolled chance '{num}'/'{LooseJesterSpring.configManager.popChance.Value}'!");
if (num <= LooseJesterSpring.configManager.popChance.Value)
{
LooseJesterSpring.Logger.LogFatal((object)"Pop!");
PlayAudio(((Component)enemyAI).gameObject);
((MonoBehaviour)enemyAI).StartCoroutine(PopJester(enemyAI));
}
}
}
private static IEnumerator PopJester(EnemyAI enemyAI)
{
if (enemyAI.currentBehaviourStateIndex < 2)
{
yield return (object)new WaitForSeconds(1f);
LooseJesterSpring.Logger.LogFatal((object)"State 1!");
enemyAI.SwitchToBehaviourStateOnLocalClient(1);
enemyAI.SwitchToBehaviourClientRpc(1);
yield return (object)new WaitForSeconds(1f);
LooseJesterSpring.Logger.LogFatal((object)"State 2!");
enemyAI.SwitchToBehaviourStateOnLocalClient(2);
enemyAI.SwitchToBehaviourClientRpc(2);
}
}
private static void PlayAudio(GameObject jesterGameObject)
{
if (LooseJesterSpring.audioClip != null)
{
AudioSource val = jesterGameObject.AddComponent<AudioSource>();
val.spatialBlend = 1f;
val.maxDistance = 100f;
val.rolloffMode = (AudioRolloffMode)0;
val.clip = LooseJesterSpring.audioClip;
val.volume = (float)LooseJesterSpring.configManager.volume.Value / 100f;
val.Play();
Object.Destroy((Object)(object)val, LooseJesterSpring.audioClip.length);
}
}
}
[HarmonyPatch(typeof(RoundManager))]
public static class RoundManagerPatch
{
[HarmonyPatch("GenerateNewLevelClientRpc")]
[HarmonyPostfix]
public static void AfterGenerateNewLevelClientRpc()
{
LooseJesterSpring.syncedRandom = new Random(StartOfRound.Instance.randomMapSeed);
}
}
}