Decompiled source of FreeThinkers v0.1.3

ArlenFreii.FreeThinkers.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FreeThinkers.Utils;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ArlenFreii.FreeThinkers")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.3.0")]
[assembly: AssemblyInformationalVersion("0.1.3+9d424b2a2ed1467f6502430edcd399226e8d47d2")]
[assembly: AssemblyProduct("FreeThinkers")]
[assembly: AssemblyTitle("ArlenFreii.FreeThinkers")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.3.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 FreeThinkers
{
	[BepInPlugin("ArlenFreii.FreeThinkers", "FreeThinkers", "0.1.3")]
	public class FreeThinkers : BaseUnityPlugin
	{
		public static FreeThinkers Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			Logger.LogInfo((object)"ArlenFreii.FreeThinkers v0.1.3 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("ArlenFreii.FreeThinkers");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ArlenFreii.FreeThinkers";

		public const string PLUGIN_NAME = "FreeThinkers";

		public const string PLUGIN_VERSION = "0.1.3";
	}
}
namespace FreeThinkers.Utils
{
	public class SharedCoroutineStarter : MonoBehaviour
	{
		private static SharedCoroutineStarter? _instance;

		public static Coroutine StartCoroutine(IEnumerator routine)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_instance == (Object)null)
			{
				_instance = new GameObject("Shared Coroutine Starter").AddComponent<SharedCoroutineStarter>();
				Object.DontDestroyOnLoad((Object)(object)_instance);
			}
			return ((MonoBehaviour)_instance).StartCoroutine(routine);
		}
	}
}
namespace FreeThinkers.Patches
{
	[HarmonyPatch(typeof(AnimatedItem))]
	public class AnimatedItem_Patches
	{
		public static AudioClip? RobotShantyClip;

		public static readonly string DefaultAudioName = "RobotToyCheer";

		[HarmonyPatch("EquipItem")]
		[HarmonyPrefix]
		public static void EquipItem_Prefix(AnimatedItem __instance)
		{
			if (RobotShantyClip == null)
			{
				FreeThinkers.Logger.LogError((object)"Toy Robot shanty clip is not initialized.");
			}
			else if ((((Object)__instance.grabAudio).name != ((Object)RobotShantyClip).name || (Object)(object)__instance.grabAudio != (Object)null) && ((Object)__instance.grabAudio).name == DefaultAudioName)
			{
				__instance.grabAudio = RobotShantyClip;
			}
		}

		public static void Load()
		{
			string filePath = Path.Combine(Paths.PluginPath, "4c69656c-FreeThinkers\\shanty2.mp3");
			SharedCoroutineStarter.StartCoroutine(LoadAudioClip(filePath));
		}

		private static IEnumerator LoadAudioClip(string filePath)
		{
			UnityWebRequest loader = UnityWebRequestMultimedia.GetAudioClip(filePath, (AudioType)13);
			loader.SendWebRequest();
			while (!loader.isDone)
			{
				yield return null;
			}
			AudioClip clip = DownloadHandlerAudioClip.GetContent(loader);
			((Object)clip).name = "ToyRobotShanty";
			RobotShantyClip = clip;
		}
	}
	[HarmonyPatch(typeof(RadMechAI))]
	public class RadMechAI_Patches
	{
		public static AudioClip? RadMechShanty;

		public static void Load()
		{
			string filePath = Path.Combine(Paths.PluginPath, "4c69656c-FreeThinkers\\shanty3.mp3");
			SharedCoroutineStarter.StartCoroutine(LoadAudioClip(filePath));
		}

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start_Postfix(RadMechAI __instance)
		{
			if (RadMechShanty == null)
			{
				FreeThinkers.Logger.LogError((object)"Old Bird shanty clip is not initialized.");
				return;
			}
			__instance.LocalLRADAudio.clip = RadMechShanty;
			__instance.LocalLRADAudio.volume = __instance.LocalLRADAudio2.volume;
			AudioSource localLRADAudio = __instance.LocalLRADAudio;
			localLRADAudio.maxDistance *= 1.5f;
			__instance.LocalLRADAudio2.volume = 0f;
		}

		private static IEnumerator LoadAudioClip(string filePath)
		{
			UnityWebRequest loader = UnityWebRequestMultimedia.GetAudioClip(filePath, (AudioType)13);
			loader.SendWebRequest();
			while (!loader.isDone)
			{
				yield return null;
			}
			AudioClip clip = DownloadHandlerAudioClip.GetContent(loader);
			((Object)clip).name = "RadMechShanty";
			RadMechShanty = clip;
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		private static void Prefix()
		{
			AnimatedItem_Patches.Load();
			RadMechAI_Patches.Load();
		}
	}
}