using System;
using System.Collections;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.Witherstyle.peak.BadToTheBonk")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1+382cc0122033b8b4123532c28020b77100953c6b")]
[assembly: AssemblyProduct("com.Witherstyle.peak.BadToTheBonk")]
[assembly: AssemblyTitle("BadToTheBonk")]
[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.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 BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BadToTheBonk
{
[BepInPlugin("com.Witherstyle.peak.BadToTheBonk", "BadToTheBonk", "1.2.1")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(Bonkable), "Awake")]
private static class BonkableAwake
{
[HarmonyPostfix]
private static void ReplaceBonkSFX(Bonkable __instance, ref SFX_Instance[] ___bonk)
{
if ((Object)(object)bonkSFX != (Object)null)
{
if (BoundConfig.removeBonkSound.Value)
{
___bonk = Array.Empty<SFX_Instance>();
}
((Component)__instance).gameObject.AddComponent<BonkSync>();
}
}
}
[HarmonyPatch(typeof(Bonkable), "Bonk")]
private static class BonkableBonk
{
[HarmonyPostfix]
private static void ReplaceBonkSFX(Bonkable __instance)
{
if ((Object)(object)bonkSFX != (Object)null)
{
BonkSync component = ((Component)__instance).GetComponent<BonkSync>();
try
{
((MonoBehaviourPun)component).photonView.RPC("RPC_PlayBonkSound", (RpcTarget)0, Array.Empty<object>());
}
catch (Exception ex)
{
Log.LogInfo((object)("Error: " + ex.Message));
}
}
}
}
internal static SFX_Instance? bonkSFX;
internal static Plugin? instance;
public const string Id = "com.Witherstyle.peak.BadToTheBonk";
internal static ManualLogSource Log { get; private set; }
internal static MyModConfig BoundConfig { get; private set; }
public static string Name => "BadToTheBonk";
public static string Version => "1.2.1";
private void Awake()
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
BoundConfig = new MyModConfig(((BaseUnityPlugin)this).Config);
Harmony val = new Harmony(Name ?? "");
val.PatchAll();
Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
LoadBonk();
}
private void LoadBonk()
{
instance = this;
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Log.LogInfo((object)("Looking for .ogg in: " + directoryName));
string[] files = Directory.GetFiles(directoryName, "*.ogg");
if (files.Length == 0)
{
Log.LogWarning((object)"No .ogg file found.");
return;
}
string text = files[0];
Log.LogInfo((object)("Found .ogg file: " + text));
((MonoBehaviour)this).StartCoroutine(LoadAudio(text));
}
private IEnumerator LoadAudio(string fileName)
{
string text = "file://" + fileName;
UnityWebRequest webRequest = UnityWebRequestMultimedia.GetAudioClip(text, (AudioType)14);
try
{
yield return webRequest.SendWebRequest();
if ((int)webRequest.result == 2 || (int)webRequest.result == 3)
{
Log.LogInfo((object)("Failed to load .ogg file: " + webRequest.error));
yield break;
}
bonkSFX = ScriptableObject.CreateInstance<SFX_Instance>();
bonkSFX.clips = (AudioClip[])(object)new AudioClip[1] { DownloadHandlerAudioClip.GetContent(webRequest) };
bonkSFX.settings = new SFX_Settings
{
volume = BoundConfig.SFXVolume.Value,
range = BoundConfig.SFXRange.Value
};
Log.LogInfo((object)("Loaded .ogg file: " + fileName));
}
finally
{
((IDisposable)webRequest)?.Dispose();
}
}
}
public class BonkSync : MonoBehaviourPun
{
[PunRPC]
public void RPC_PlayBonkSound()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
Plugin.bonkSFX.Play(((Component)this).transform.position);
}
}
public class MyModConfig
{
public readonly ConfigEntry<bool> randomizePitch;
public readonly ConfigEntry<int> staticPitch;
public readonly ConfigEntry<bool> removeBonkSound;
public readonly ConfigEntry<float> SFXVolume;
public readonly ConfigEntry<float> SFXRange;
public MyModConfig(ConfigFile cfg)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
cfg.SaveOnConfigSet = false;
randomizePitch = cfg.Bind<bool>("Randomizer", "Randomize Pitch", false, "If enabled, randomizes the pitch/speed of audio whenever bonked. [Currently Disabled]");
staticPitch = cfg.Bind<int>("Randomizer", "Static Pitch Value", 0, new ConfigDescription("If randomizer is disabled, this is the pitch that will play (0 is high, 5 is low). [Currently Disabled]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 5), Array.Empty<object>()));
removeBonkSound = cfg.Bind<bool>("General", "Remove Original Bonk Sound", false, "If enabled, removes the original bonk sound (only affects the host).");
SFXVolume = cfg.Bind<float>("General", "Bonk Volume", 1f, "Volume of bonk.");
SFXRange = cfg.Bind<float>("General", "Bonk Range", 50f, "Maximum distance bonk can be heard from.");
ClearOrphanedEntries(cfg);
cfg.Save();
cfg.SaveOnConfigSet = true;
}
private static void ClearOrphanedEntries(ConfigFile cfg)
{
PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg);
dictionary.Clear();
}
}
}
namespace BadToTheBonk.Config
{
internal static class MyModConfig
{
public static ConfigEntry<bool> randomizePitch;
public static ConfigEntry<int> staticPitch;
public static void Bind(ConfigFile cfg)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
cfg.SaveOnConfigSet = false;
randomizePitch = cfg.Bind<bool>("Randomizer", "Randomize Pitch", true, "If enabled, randomizes the pitch/speed of audio whenever bonked.");
staticPitch = cfg.Bind<int>("Randomizer", "Static Pitch Value", 3, new ConfigDescription("If randomizer is disabled, this is the pitch that will play (0 is high, 5 is low).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 5), Array.Empty<object>()));
ClearOrphanedEntries(cfg);
cfg.Save();
cfg.SaveOnConfigSet = true;
}
private static void ClearOrphanedEntries(ConfigFile cfg)
{
PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg);
dictionary.Clear();
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}