Decompiled source of WeskerThumper v0.0.1

BepInEx/plugins/WeskerThumper/WeskerThumper.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

[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 = "")]
[assembly: AssemblyCompany("WeskerThumper")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WeskerThumper")]
[assembly: AssemblyTitle("WeskerThumper")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace WeskerThumper;

public static class CrawlerPatcher
{
	private static Dictionary<UnityWebRequestAsyncOperation, int> requests = new Dictionary<UnityWebRequestAsyncOperation, int>();

	public static AudioClip[] weskerSpotted = (AudioClip[])(object)new AudioClip[3];

	public static AudioClip[] weskerBash = (AudioClip[])(object)new AudioClip[1];

	public static void Init()
	{
		Harmony.CreateAndPatchAll(typeof(CrawlerPatcher), (string)null);
		for (int i = 0; i < 3; i++)
		{
			UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip("file://" + Plugin.BuildSoundPath("Thumper/spotted_" + (i + 1) + ".ogg"), (AudioType)14);
			UnityWebRequestAsyncOperation val = audioClip.SendWebRequest();
			requests[val] = i;
			((AsyncOperation)val).completed += ThumperSpotted;
		}
		UnityWebRequest audioClip2 = UnityWebRequestMultimedia.GetAudioClip("file://" + Plugin.BuildSoundPath("Thumper/bash.ogg"), (AudioType)14);
		UnityWebRequestAsyncOperation val2 = audioClip2.SendWebRequest();
		((AsyncOperation)val2).completed += ThumperBash;
	}

	private static void ThumperSpotted(AsyncOperation operation)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		UnityWebRequestAsyncOperation val = (UnityWebRequestAsyncOperation)operation;
		weskerSpotted[requests[val]] = DownloadHandlerAudioClip.GetContent(val.webRequest);
		Debug.Log((object)("Sppotted file (" + requests[val] + ") loaded!"));
	}

	private static void ThumperBash(AsyncOperation operation)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		UnityWebRequestAsyncOperation val = (UnityWebRequestAsyncOperation)operation;
		weskerBash[0] = DownloadHandlerAudioClip.GetContent(val.webRequest);
		Debug.Log((object)"Bash file loaded!");
	}

	[HarmonyPatch(typeof(CrawlerAI), "CollideWithWallClientRpc")]
	[HarmonyPostfix]
	private static void Postfix_CollideWithWallClientRpc(CrawlerAI __instance)
	{
		RoundManager.PlayRandomClip(((EnemyAI)__instance).creatureVoice, weskerBash, true, 2f, 0);
	}

	[HarmonyPatch(typeof(CrawlerAI), "Start")]
	[HarmonyPostfix]
	private static void Postfix_Start(CrawlerAI __instance)
	{
		__instance.longRoarSFX = weskerSpotted;
		((EnemyAI)__instance).creatureVoice.volume = 2f;
	}

	[HarmonyPatch(typeof(CrawlerAI), "MakeScreech")]
	[HarmonyPrefix]
	private static void Prefix_MakeScreech(CrawlerAI __instance)
	{
		((EnemyAI)__instance).creatureVoice.volume = 2f;
	}

	[HarmonyPatch(typeof(CrawlerAI), "Update")]
	[HarmonyPostfix]
	private static void Postfix_Update(CrawlerAI __instance)
	{
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		if (((EnemyAI)__instance).isEnemyDead)
		{
			return;
		}
		Type typeFromHandle = typeof(CrawlerAI);
		if (!(bool)typeFromHandle.InvokeMember("hasEnteredChaseMode", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField, null, __instance, null) || (bool)typeFromHandle.InvokeMember("lostPlayerInChase", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField, null, __instance, null))
		{
			return;
		}
		if ((Object)(object)((EnemyAI)__instance).targetPlayer == (Object)(object)GameNetworkManager.Instance.localPlayerController)
		{
			LocalPlayer.Instance.UpdateChase(EnemyType.Thumper);
			return;
		}
		Vector3 position = ((Component)GameNetworkManager.Instance.localPlayerController.gameplayCamera).gameObject.transform.position;
		if ((double)Vector3.Distance(position, ((EnemyAI)__instance).eye.position) <= 200.0)
		{
			LocalPlayer.Instance.UpdateChase(EnemyType.Thumper);
		}
	}
}
public enum EnemyType : uint
{
	Thumper,
	Max
}
public class LocalPlayer : MonoBehaviour
{
	public static LocalPlayer Instance = null;

	public AudioSource chaseAudio = null;

	private float[] lastChaseTime = new float[1];

	private static AudioClip[] chaseMusic = (AudioClip[])(object)new AudioClip[1];

	public static void Init()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		new GameObject("LocalPlayer", new Type[1] { typeof(LocalPlayer) }).GetComponent<LocalPlayer>();
	}

	public static void Precache()
	{
		UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip("file://" + Plugin.BuildSoundPath("Thumper/chase.ogg"), (AudioType)14);
		UnityWebRequestAsyncOperation val = audioClip.SendWebRequest();
		((AsyncOperation)val).completed += ThumperChase;
	}

	private static void ThumperChase(AsyncOperation operation)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		chaseMusic[0] = DownloadHandlerAudioClip.GetContent(((UnityWebRequestAsyncOperation)operation).webRequest);
		Debug.Log((object)"Thumper music loaded!");
	}

	public virtual void Start()
	{
		if ((Object)(object)Instance != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)Instance).gameObject);
		}
		Instance = this;
		chaseAudio = ((Component)this).gameObject.AddComponent<AudioSource>();
		chaseAudio.loop = true;
		chaseAudio.spatialBlend = 0f;
		chaseAudio.spatialize = false;
		chaseAudio.volume = 0f;
		Object.DontDestroyOnLoad((Object)(object)this);
		Debug.Log((object)"Local player instantiated!");
	}

	public void UpdateChase(EnemyType type)
	{
		lastChaseTime[(uint)type] = Time.time;
	}

	public virtual void Update()
	{
		float time = Time.time;
		if ((double)time <= 1.0)
		{
			return;
		}
		if ((double)(time - lastChaseTime[0]) <= 1.0)
		{
			if (!chaseAudio.isPlaying)
			{
				chaseAudio.clip = chaseMusic[0];
				chaseAudio.volume = 0.1f;
				chaseAudio.Play();
			}
			else if (chaseAudio.volume < 0.6f)
			{
				AudioSource obj = chaseAudio;
				obj.volume += 0.2f * Time.deltaTime;
				if (chaseAudio.volume > 0.6f)
				{
					chaseAudio.volume = 0.6f;
				}
			}
		}
		else if (chaseAudio.isPlaying && (double)chaseAudio.volume > 0.0)
		{
			AudioSource obj2 = chaseAudio;
			obj2.volume -= 0.2f * Time.deltaTime;
			if (chaseAudio.volume < 0f)
			{
				chaseAudio.volume = 0f;
				chaseAudio.Stop();
			}
		}
	}
}
[BepInPlugin("WeskerThumper", "WeskerThumper", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private void Awake()
	{
		CrawlerPatcher.Init();
		TimeOfDayPatcher.Init();
		LocalPlayer.Precache();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin WeskerThumper is loaded!");
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		if ((Object)(object)LocalPlayer.Instance == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Creating local player...");
			LocalPlayer.Init();
		}
	}

	public static string BuildSoundPath(string path)
	{
		return Paths.PluginPath + "/WeskerThumper/SFX/" + path;
	}
}
public class TimeOfDayPatcher
{
	private static AudioClip[] dayTimeMusic = (AudioClip[])(object)new AudioClip[1];

	private static AudioClip menuTheme = null;

	private static MenuManager mainMenuInstance = null;

	public static void Init()
	{
		Harmony.CreateAndPatchAll(typeof(TimeOfDayPatcher), (string)null);
		UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip("file://" + Plugin.BuildSoundPath("Ambient/dawn.ogg"), (AudioType)14);
		UnityWebRequestAsyncOperation val = audioClip.SendWebRequest();
		((AsyncOperation)val).completed += DayTimeMusic;
		audioClip = UnityWebRequestMultimedia.GetAudioClip("file://" + Plugin.BuildSoundPath("Ambient/main_menu.ogg"), (AudioType)14);
		val = audioClip.SendWebRequest();
		((AsyncOperation)val).completed += MainMenuMusic;
	}

	private static void MainMenuMusic(AsyncOperation operation)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		UnityWebRequestAsyncOperation val = (UnityWebRequestAsyncOperation)operation;
		menuTheme = DownloadHandlerAudioClip.GetContent(val.webRequest);
		if ((Object)(object)mainMenuInstance != (Object)null)
		{
			PatchMenuManager(mainMenuInstance);
		}
		Debug.Log((object)"Main menu music loaded!");
	}

	private static void DayTimeMusic(AsyncOperation operation)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		UnityWebRequestAsyncOperation val = (UnityWebRequestAsyncOperation)operation;
		dayTimeMusic[0] = DownloadHandlerAudioClip.GetContent(val.webRequest);
		Debug.Log((object)"Daytime music loaded!");
		if ((Object)(object)SoundManager.Instance != (Object)null)
		{
			PatchSoundManager(SoundManager.Instance);
		}
		if ((Object)(object)TimeOfDay.Instance != (Object)null)
		{
			PatchTimeOfDay(TimeOfDay.Instance);
		}
	}

	private static void PatchSoundManager(SoundManager instance)
	{
		instance.DaytimeMusic = dayTimeMusic;
		Debug.Log((object)"Daytime music patched!");
	}

	private static void PatchTimeOfDay(TimeOfDay instance)
	{
		instance.timeOfDayCues[0] = dayTimeMusic[0];
		instance.timeOfDayCues[1] = dayTimeMusic[0];
	}

	private static void PatchMenuManager(MenuManager instance)
	{
		mainMenuInstance = instance;
		instance.menuMusic = menuTheme;
		if (!instance.isInitScene)
		{
			instance.MenuAudio = ((Component)instance).gameObject.AddComponent<AudioSource>();
			instance.MenuAudio.volume = 0.7f;
			instance.MenuAudio.loop = true;
			instance.MenuAudio.spatialize = false;
			instance.MenuAudio.spatialBlend = 0f;
			instance.MenuAudio.clip = menuTheme;
			instance.MenuAudio.Play();
		}
	}

	[HarmonyPatch(typeof(SoundManager), "Start")]
	[HarmonyPostfix]
	private static void Postfix_SndManagerStart(SoundManager __instance)
	{
		PatchSoundManager(__instance);
	}

	[HarmonyPatch(typeof(TimeOfDay), "Start")]
	[HarmonyPostfix]
	private static void Postfix_TimeOfDayStart(TimeOfDay __instance)
	{
		PatchTimeOfDay(__instance);
	}

	[HarmonyPatch(typeof(MenuManager), "Start")]
	[HarmonyPrefix]
	private static void Prefix_MenuManagerStart(MenuManager __instance)
	{
		__instance.menuMusic = null;
		__instance.MenuAudio = null;
	}

	[HarmonyPatch(typeof(MenuManager), "Start")]
	[HarmonyPostfix]
	private static void Postfix_MenuManagerStart(MenuManager __instance)
	{
		PatchMenuManager(__instance);
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "WeskerThumper";

	public const string PLUGIN_NAME = "WeskerThumper";

	public const string PLUGIN_VERSION = "1.0.0";
}