Decompiled source of AoTGiants v1.1.0

BepInEx/plugins/Flowprojects-AoTGiants/AoTGiants.dll

Decompiled 10 months ago
using System;
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 AoTGiants.Patches;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
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("AoTGiants")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AoTGiants")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2937c08c-0471-49a4-b87f-168a8f4f24d6")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AoTGiants
{
	[BepInPlugin("Flowprojects.AoTGiants", "AoT Giants", "1.1.0")]
	public class AotGiantsBase : BaseUnityPlugin
	{
		private const string pluginGUID = "Flowprojects.AoTGiants";

		private const string pluginName = "AoT Giants";

		private const string pluginVersion = "1.1.0";

		private const string assetBundleName = "aotgiantsassets";

		internal const float DefaultSFXVolume = 0.3f;

		internal static ConfigEntry<string> configVolume;

		private readonly Harmony harmony = new Harmony("Flowprojects.AoTGiants");

		private static AotGiantsBase Instance;

		internal static List<AudioClip> SoundFX;

		internal static AssetBundle Bundle;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			configVolume = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Volume", "30", "Volume of the music (in percent)");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Flowprojects.AoTGiants is loaded!");
			string text = "AoTGiants.dll";
			string text2 = ((BaseUnityPlugin)this).Info.Location.TrimEnd(text.ToCharArray());
			SoundFX = new List<AudioClip>();
			Bundle = AssetBundle.LoadFromFile(text2 + "aotgiantsassets");
			if ((Object)(object)Bundle != (Object)null)
			{
				SoundFX = Bundle.LoadAllAssets<AudioClip>().ToList();
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Successfully loaded asset bundle!");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load assetbundle!");
			}
			harmony.PatchAll(typeof(ForestGiantAIPatch));
		}

		internal static float getVolume(string volume)
		{
			try
			{
				return (float)Convert.ToDouble(volume) / 100f;
			}
			catch (Exception)
			{
				return 0.3f;
			}
		}
	}
}
namespace AoTGiants.Patches
{
	[HarmonyPatch(typeof(ForestGiantAI))]
	internal class ForestGiantAIPatch
	{
		private static ManualLogSource logger = Logger.CreateLogSource("Flowprojects.AoTGiants.ForestGiantAIPatch");

		private static AudioSource aotSFX;

		private static string sfxVolume = AotGiantsBase.configVolume.Value;

		[HarmonyPatch("GiantSeePlayerEffect")]
		[HarmonyPrefix]
		private static void forestGiantAoTAudioPatch(ForestGiantAI __instance)
		{
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			aotSFX = GameNetworkManager.Instance.localPlayerController.itemAudio;
			aotSFX.volume = AotGiantsBase.getVolume(sfxVolume);
			bool flag = false;
			if (!flag)
			{
				flag = (bool)Traverse.Create((object)__instance).Field("lostPlayerInChase").GetValue();
			}
			if (GameNetworkManager.Instance.localPlayerController.isPlayerDead || GameNetworkManager.Instance.localPlayerController.isInsideFactory)
			{
				return;
			}
			if (((EnemyAI)__instance).currentBehaviourStateIndex == 1 && (Object)(object)__instance.chasingPlayer == (Object)(object)GameNetworkManager.Instance.localPlayerController && !flag)
			{
				GameNetworkManager.Instance.localPlayerController.IncreaseFearLevelOverTime(1.4f, 1f);
				if (!aotSFX.isPlaying)
				{
					playRandomTitanAggroClip(aotSFX);
				}
				return;
			}
			bool flag2 = false;
			if (!GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom && ((EnemyAI)__instance).HasLineOfSightToPosition(((Component)GameNetworkManager.Instance.localPlayerController.gameplayCamera).transform.position, 45f, 70, -1f))
			{
				if (Vector3.Distance(((Component)__instance).transform.position, ((Component)GameNetworkManager.Instance.localPlayerController).transform.position) < 15f)
				{
					GameNetworkManager.Instance.localPlayerController.JumpToFearLevel(0.7f, true);
				}
				else
				{
					GameNetworkManager.Instance.localPlayerController.JumpToFearLevel(0.4f, true);
				}
			}
			if (flag)
			{
				aotSFX.Stop();
				logger.LogInfo((object)"Stopped audio clip");
			}
		}

		private static void playRandomTitanAggroClip(AudioSource __audioSource)
		{
			int index = Random.Range(0, AotGiantsBase.SoundFX.Count);
			__audioSource.PlayOneShot(AotGiantsBase.SoundFX[index]);
			logger.LogInfo((object)("Played audio clip " + index + " with volume " + aotSFX.volume));
		}
	}
}