Decompiled source of Rondelim v0.0.1

plugins/Rondelim/Rondelim.dll

Decompiled 6 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Timers;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Rondelim.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Rondelim")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Rondelim")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6f87b4df-1a9d-47b5-b714-8522dbf0e7a4")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Rondelim
{
	[BepInPlugin("Dardale.Rondelim", "Rondelim", "1.0.0")]
	public class RondelimBase : BaseUnityPlugin
	{
		private const string modGUID = "Dardale.Rondelim";

		private const string modName = "Rondelim";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Dardale.Rondelim");

		private static RondelimBase Instance;

		internal ManualLogSource mls;

		internal static List<AudioClip> SoundFX;

		internal static AssetBundle Bundle;

		internal static Timer RondelimTimer;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Dardale.Rondelim");
			mls.LogInfo((object)"Rondelim has awaken");
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			mls = ((BaseUnityPlugin)this).Logger;
			RondelimTimer = new Timer();
			RondelimTimer.Interval = 10000.0;
			SoundFX = new List<AudioClip>();
			string location = ((BaseUnityPlugin)Instance).Info.Location;
			location = location.TrimEnd("Rondelim.dll".ToCharArray());
			Bundle = AssetBundle.LoadFromFile(location + "rondelim");
			if ((Object)(object)Bundle != (Object)null)
			{
				mls.LogInfo((object)("folder: " + location));
				mls.LogInfo((object)"Succesfully loaded asset bundle");
				SoundFX = Bundle.LoadAllAssets<AudioClip>().ToList();
			}
			else
			{
				mls.LogError((object)"Unable to load asset bundle");
			}
		}
	}
}
namespace Rondelim.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void TimerPlaySound(PlayerControllerB __instance)
		{
			ManualLogSource mls = Logger.CreateLogSource("TimerPlaySound");
			bool shouldPlaySound = false;
			string playerUsername = __instance.playerUsername;
			RondelimBase.RondelimTimer.Elapsed += playSound;
			ulong playerSteamId = __instance.playerSteamId;
			if (!(playerUsername == "PokoLoco"))
			{
				return;
			}
			if (__instance.isInsideFactory)
			{
				if (!RondelimBase.RondelimTimer.Enabled)
				{
					mls.LogInfo((object)(playerUsername + " Inside Facility"));
					shouldPlaySound = true;
					RondelimBase.RondelimTimer.Enabled = true;
				}
			}
			else if (RondelimBase.RondelimTimer.Enabled)
			{
				mls.LogInfo((object)(playerUsername + " Exited Facility"));
				RondelimBase.RondelimTimer.Enabled = false;
				shouldPlaySound = false;
			}
			void playSound(object sender, ElapsedEventArgs e)
			{
				mls.LogInfo((object)"Inside playSound - shouldPlaySound value is");
				mls.LogInfo((object)shouldPlaySound);
				if (shouldPlaySound)
				{
					__instance.movementAudio.PlayOneShot(RondelimBase.SoundFX[0]);
					shouldPlaySound = false;
				}
			}
		}
	}
}