Decompiled source of RitualGongFix v1.0.0

RitualGongFix.dll

Decompiled an hour ago
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using On.RoR2;
using R2API;
using R2API.Utils;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RitualGongFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RitualGongFix")]
[assembly: AssemblyTitle("RitualGongFix")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RitualGongFix;

[BepInPlugin("com.vegard.ritualgongfix", "RitualGongFix", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class RitualGongFixPlugin : BaseUnityPlugin
{
	public const string GUID = "com.vegard.ritualgongfix";

	public const string Version = "1.0.0";

	private const string HitEvent = "Play_RitualGong_Hit";

	internal static ManualLogSource Log;

	private static ConfigEntry<float> minTimeBetweenRings;

	private static ConfigEntry<bool> logRings;

	private static readonly Dictionary<int, float> lastRing = new Dictionary<int, float>();

	private void Awake()
	{
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		minTimeBetweenRings = ((BaseUnityPlugin)this).Config.Bind<float>("Sound", "Min time between rings", 0.15f, "Seconds. Hits on the same gong closer together than this ring it only once.");
		logRings = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Log rings", false, "Write a line to the BepInEx log every time the gong rings.");
		string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "RitualGongSoundbank.bnk");
		if (!File.Exists(path))
		{
			Log.LogError((object)"RitualGongSoundbank.bnk not found next to the DLL; the gong will stay silent.");
			return;
		}
		SoundBanks.Add(File.ReadAllBytes(path));
		TrialGongInteraction.ApplyForceOnGongRigidbodyInternal += new hook_ApplyForceOnGongRigidbodyInternal(OnGongStruck);
		TrialGongInteraction.OnIncomingDamageServer += new hook_OnIncomingDamageServer(OnGongDamaged);
		Log.LogInfo((object)"Ritual Gong Fix loaded.");
	}

	private static void OnGongDamaged(orig_OnIncomingDamageServer orig, TrialGongInteraction self, DamageInfo info)
	{
		if (info != null && !Object.op_Implicit((Object)(object)info.inflictedHurtbox) && Object.op_Implicit((Object)(object)self.mainHurtBox))
		{
			info.inflictedHurtbox = self.mainHurtBox;
		}
		orig.Invoke(self, info);
	}

	private static void OnGongStruck(orig_ApplyForceOnGongRigidbodyInternal orig, TrialGongInteraction self, Vector3 force)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		orig.Invoke(self, force);
		if (!Object.op_Implicit((Object)(object)self))
		{
			return;
		}
		int instanceID = ((Object)self).GetInstanceID();
		float unscaledTime = Time.unscaledTime;
		if (!lastRing.TryGetValue(instanceID, out var value) || !(unscaledTime - value < minTimeBetweenRings.Value))
		{
			lastRing[instanceID] = unscaledTime;
			GameObject val = (Object.op_Implicit((Object)(object)self.gongRigidBody) ? ((Component)self.gongRigidBody).gameObject : ((Component)self).gameObject);
			Util.PlaySound("Play_RitualGong_Hit", val);
			if (logRings.Value)
			{
				Log.LogInfo((object)$"Gong rang (force {((Vector3)(ref force)).magnitude:0.0}).");
			}
		}
	}
}