Decompiled source of YeahTruck v1.1.2

LCYeahTruck.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
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 GameNetcodeStuff;
using HarmonyLib;
using LCYeahTruck.Patches;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: AssemblyCompany("LCYeahTruck")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Yeah Truck")]
[assembly: AssemblyTitle("LCYeahTruck")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LCYeahTruck
{
	[BepInPlugin("raptureawaits.yeahtruck", "YeahTruck", "1.1.2")]
	public class YeahTruckBase : BaseUnityPlugin
	{
		private const string mod_guid = "raptureawaits.yeahtruck";

		private const string mod_name = "YeahTruck";

		private const string mod_version = "1.1.2";

		internal static YeahTruckBase instance;

		internal static ManualLogSource modlog;

		private readonly Harmony harmony = new Harmony("raptureawaits.yeahtruck");

		public static AssetBundle new_sounds;

		private AudioClip _yeah_clip;

		public float yeah_volume = 0.7f;

		public double flip_threshold = 135.0;

		public double correct_threshold = 150.0;

		public TimeSpan cooldown_seconds = new TimeSpan(0, 0, 5);

		public HashSet<int> cool_vehicles = new HashSet<int>();

		public Dictionary<int, DateTime> cooldowns = new Dictionary<int, DateTime>();

		public AudioClip yeah_clip
		{
			get
			{
				return _yeah_clip;
			}
			set
			{
				_yeah_clip = value;
			}
		}

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			modlog = Logger.CreateLogSource("YeahTruck");
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			new_sounds = AssetBundle.LoadFromFile(Path.Combine(directoryName, "yeah-truck"));
			if ((Object)(object)new_sounds == (Object)null)
			{
				modlog.LogError((object)"Failed to load AssetBundle.");
				return;
			}
			AudioClip[] array = new_sounds.LoadAssetWithSubAssets<AudioClip>("assets\\audio\\ye_fade.wav");
			if (array != null && array.Length != 0)
			{
				AudioClip val = array[0];
				instance.yeah_clip = val;
			}
			else
			{
				modlog.LogError((object)"Failed to load YEAH audio data from extracted assets.");
			}
			harmony.PatchAll(typeof(YeahTruckPatch));
			modlog.LogInfo((object)"Plugin raptureawaits.yeahtruck is loaded!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LCYeahTruck";

		public const string PLUGIN_NAME = "Yeah Truck";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LCYeahTruck.Patches
{
	[HarmonyPatch(typeof(VehicleController))]
	internal class YeahTruckPatch
	{
		internal static ManualLogSource modlog = YeahTruckBase.modlog;

		internal static YeahTruckBase b = YeahTruckBase.instance;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPostfix(VehicleController __instance)
		{
			int instanceID = ((Object)((Component)__instance).gameObject).GetInstanceID();
			b.cool_vehicles.Add(instanceID);
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePostfix(VehicleController __instance, ref Quaternion ___syncedRotation, ref AudioSource ___radioAudio, ref PlayerControllerB ___currentDriver, ref bool ___magnetedToShip, ref WheelCollider ___FrontLeftWheel, ref WheelCollider ___FrontRightWheel, ref WheelCollider ___BackLeftWheel, ref WheelCollider ___BackRightWheel)
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			int instanceID = ((Object)((Component)__instance).gameObject).GetInstanceID();
			bool flag = b.cooldowns.ContainsKey(instanceID);
			if (flag && DateTime.Now > b.cooldowns[instanceID])
			{
				b.cooldowns.Remove(instanceID);
				flag = false;
			}
			if (!b.cool_vehicles.Contains(instanceID) & ___magnetedToShip)
			{
				b.cool_vehicles.Add(instanceID);
			}
			bool flag2 = !b.cool_vehicles.Contains(instanceID) && (Object)(object)___currentDriver != (Object)null && !___magnetedToShip;
			Vector3 eulerAngles = ((Quaternion)(ref ___syncedRotation)).eulerAngles;
			double num = Math.Abs((double)((Vector3)(ref eulerAngles))[2] - 180.0);
			if (num < b.flip_threshold && flag2)
			{
				b.cool_vehicles.Add(instanceID);
				if (!flag)
				{
					___radioAudio.PlayOneShot(b.yeah_clip, b.yeah_volume);
					modlog.LogInfo((object)"Truck has been flipped! YEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAA-");
					b.cooldowns.Add(instanceID, DateTime.Now + b.cooldown_seconds);
				}
			}
			bool flag3 = !___FrontLeftWheel.isGrounded && !___FrontRightWheel.isGrounded && !___BackLeftWheel.isGrounded && !___BackRightWheel.isGrounded;
			if (flag3 && flag2)
			{
				b.cool_vehicles.Add(instanceID);
				if (!flag)
				{
					___radioAudio.PlayOneShot(b.yeah_clip, b.yeah_volume);
					modlog.LogInfo((object)"Truck is airborne! YEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAA-");
					b.cooldowns.Add(instanceID, DateTime.Now + b.cooldown_seconds);
				}
			}
			bool flag4 = ___FrontLeftWheel.isGrounded && ___FrontRightWheel.isGrounded && ___BackLeftWheel.isGrounded && ___BackRightWheel.isGrounded;
			if (b.cool_vehicles.Contains(instanceID) && num > b.correct_threshold && flag4 && !___magnetedToShip)
			{
				b.cool_vehicles.Remove(instanceID);
				modlog.LogInfo((object)"Truck is boring again.");
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class FlipResetPatch
	{
		internal static ManualLogSource modlog = YeahTruckBase.modlog;

		internal static YeahTruckBase b = YeahTruckBase.instance;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPostfix()
		{
			b.cool_vehicles.Clear();
			b.cooldowns.Clear();
			modlog.LogInfo((object)"Reset cool vehicles.");
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}