using System;
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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CritHits.Patches;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("CritHits")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CritHits")]
[assembly: AssemblyTitle("CritHits")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 CritHits
{
[BepInPlugin("CritHits", "CritHits", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
private const string GUID = "CritHits";
private const string VERSION = "1.0.1";
public static ManualLogSource Logger;
private static readonly Harmony Harmony = new Harmony("CritHits");
private static AssetBundle _bundle;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
SetConfig();
LoadAssets();
Harmony.PatchAll();
Logger.LogInfo((object)"Plugin CritHits (1.0.1) is loaded!");
}
private void SetConfig()
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Expected O, but got Unknown
//IL_0048: Expected O, but got Unknown
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Expected O, but got Unknown
//IL_0084: Expected O, but got Unknown
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Expected O, but got Unknown
//IL_00c0: Expected O, but got Unknown
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Expected O, but got Unknown
//IL_0109: Expected O, but got Unknown
string text = "General";
ShovelPatch._critRate = ((BaseUnityPlugin)this).Config.Bind<double>(new ConfigDefinition(text, "Critical Hit Rate"), ShovelPatch._critRate, new ConfigDescription("Chance to perform a critical hit.", (AcceptableValueBase)(object)new AcceptableValueRange<double>(0.0, 1.0), Array.Empty<object>())).Value;
ShovelPatch._critDamage = ((BaseUnityPlugin)this).Config.Bind<int>(new ConfigDefinition(text, "Critical Damage"), ShovelPatch._critDamage, new ConfigDescription("Damage dealt by a critical hit.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())).Value;
ShovelPatch._baseDamage = ((BaseUnityPlugin)this).Config.Bind<int>(new ConfigDefinition(text, "Base Damage"), ShovelPatch._baseDamage, new ConfigDescription("Damage dealt by a normal hit.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())).Value;
text = "AVFX";
ShovelPatch._addSfx = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "Use Critical Hit Sound Effect"), ShovelPatch._addSfx, new ConfigDescription("Whether to play the critical hit sound effect.", (AcceptableValueBase)(object)new AcceptableValueList<bool>(new bool[2] { true, false }), Array.Empty<object>())).Value;
}
private void LoadAssets()
{
LoadBundle();
if (_bundle != null)
{
AudioClip val = SafeLoadAsset<AudioClip>("assets/sfx/crithit.wav");
if (val != null)
{
ShovelPatch._critHitSfxs = (AudioClip[])(object)new AudioClip[1] { val };
Logger.LogDebug((object)"Loaded critHitSfx");
}
}
}
private void LoadBundle()
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string n) => n.StartsWith("CritHits.Assets"));
if (text == null)
{
Logger.LogError((object)"Embedded resource for [CritHits] not found!");
return;
}
try
{
Logger.LogInfo((object)("Loading embedded resource data [" + text + "]..."));
using Stream stream = executingAssembly.GetManifestResourceStream(text);
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
_bundle = AssetBundle.LoadFromMemory(memoryStream.ToArray());
}
catch
{
Logger.LogError((object)("Bundle [" + text + "] failed to load!"));
return;
}
Logger.LogInfo((object)("Bundle [" + text + "] accessible!"));
Logger.LogDebug((object)string.Join(", ", _bundle.GetAllAssetNames()));
}
private T SafeLoadAsset<T>(string assetName) where T : Object
{
AssetBundle bundle = _bundle;
if (bundle == null || !bundle.GetAllAssetNames().Contains(assetName))
{
Logger.LogError((object)("Asset [" + assetName + "] not found in bundle [" + ((Object)_bundle).name + "]!"));
return default(T);
}
return _bundle.LoadAsset<T>(assetName);
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "CritHits";
public const string PLUGIN_NAME = "CritHits";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace CritHits.Patches
{
[HarmonyPatch(typeof(Shovel), "SwingShovel")]
public class ShovelPatch
{
public static readonly Random _random = new Random();
public static double _critRate = 0.05;
public static int _critDamage = 5;
public static int _baseDamage = 1;
public static bool _addSfx = true;
public static AudioClip[] _critHitSfxs = Array.Empty<AudioClip>();
public static AudioClip[] _baseHitSfxs;
private static bool _isCrit;
public static void Prefix(Shovel __instance, bool cancel = false)
{
if (_baseHitSfxs == null)
{
_baseHitSfxs = __instance.hitSFX;
}
_isCrit = _random.NextDouble() < _critRate;
if (_addSfx)
{
__instance.hitSFX = (_isCrit ? _critHitSfxs : _baseHitSfxs);
Plugin.Logger.LogDebug((object)string.Join(", ", __instance.hitSFX.Select((AudioClip a) => ((Object)a).name)));
}
__instance.shovelHitForce = (_isCrit ? _critDamage : _baseDamage);
Plugin.Logger.LogDebug((object)__instance.shovelHitForce);
}
}
}