Decompiled source of BlindBirdStringEnjoyersImprovements v1.7.0

BlindBirdStringEnjoyersImprovements.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using BlindBirdStringEnjoyersImprovements.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("UnityEngine")]
[assembly: AssemblyCompany("BlindBirdStringEnjoyersImprovements")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("General game improvements")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BlindBirdStringEnjoyersImprovements")]
[assembly: AssemblyTitle("BlindBirdStringEnjoyersImprovements")]
[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 BlindBirdStringEnjoyersImprovements
{
	public class FancyLampToggle : PhysicsProp
	{
		private Light m_Light;

		private AudioSource m_AudioSource;

		public AudioClip[] AudioClips;

		public override void Start()
		{
			m_Light = ((Component)this).GetComponentInChildren<Light>();
			m_AudioSource = ((Component)this).GetComponentInChildren<AudioSource>();
			((GrabbableObject)this).Start();
			((GrabbableObject)this).isBeingUsed = true;
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			((Behaviour)m_Light).enabled = used;
			if ((Object)(object)m_AudioSource != (Object)null && AudioClips != null && AudioClips.Length != 0)
			{
				m_AudioSource.PlayOneShot(AudioClips[Random.Range(0, AudioClips.Length)]);
				RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, 7f, 0.4f, 0, ((GrabbableObject)this).isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
			}
		}
	}
	[BepInPlugin("BlindBirdStringEnjoyersImprovements", "BlindBirdStringEnjoyersImprovements", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("BlindBirdStringEnjoyersImprovements");

		public static ManualLogSource LogSource;

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin BlindBirdStringEnjoyersImprovements is loaded!");
			LogSource = Logger.CreateLogSource("BlindBirdStringEnjoyersImprovements");
			harmony.PatchAll(typeof(EntranceTeleportPatch));
			harmony.PatchAll(typeof(GrabbableObjectPatch));
			harmony.PatchAll(typeof(StormyWeatherPatch));
			harmony.PatchAll(typeof(HUDManagerPatch));
			harmony.PatchAll(typeof(GameNetworkManagerPatch));
			harmony.PatchAll(typeof(PreInitSceneScriptPatch));
			LogSource.LogInfo((object)"Patched!");
		}
	}
	public static class Utils
	{
		public static void CopyGrabbablePrefab<T>(GrabbableObject baseObj, T newObj) where T : GrabbableObject
		{
			((GrabbableObject)newObj).customGrabTooltip = baseObj.customGrabTooltip;
			((GrabbableObject)newObj).floorYRot = baseObj.floorYRot;
			((GrabbableObject)newObj).grabbable = baseObj.grabbable;
			((GrabbableObject)newObj).grabbableToEnemies = baseObj.grabbableToEnemies;
			((GrabbableObject)newObj).isInElevator = baseObj.isInElevator;
			((GrabbableObject)newObj).isInFactory = baseObj.isInFactory;
			((GrabbableObject)newObj).isInShipRoom = baseObj.isInShipRoom;
			((GrabbableObject)newObj).itemProperties = baseObj.itemProperties;
			((GrabbableObject)newObj).propBody = baseObj.propBody;
			((GrabbableObject)newObj).propColliders = baseObj.propColliders;
			((GrabbableObject)newObj).radarIcon = baseObj.radarIcon;
			((GrabbableObject)newObj).useCooldown = baseObj.useCooldown;
		}

		public static void CopyAudioSource(AudioSource original, AudioSource dest)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			dest.clip = original.clip;
			dest.dopplerLevel = original.dopplerLevel;
			dest.ignoreListenerPause = original.ignoreListenerPause;
			dest.ignoreListenerVolume = original.ignoreListenerVolume;
			dest.loop = original.loop;
			dest.maxDistance = original.maxDistance;
			dest.minDistance = original.minDistance;
			dest.mute = original.mute;
			dest.outputAudioMixerGroup = original.outputAudioMixerGroup;
			dest.panStereo = original.panStereo;
			dest.pitch = original.pitch;
			dest.playOnAwake = original.playOnAwake;
			dest.priority = original.priority;
			dest.reverbZoneMix = original.reverbZoneMix;
			dest.rolloffMode = original.rolloffMode;
			dest.spatialBlend = original.spatialBlend;
			dest.spatialize = original.spatialize;
			dest.spatializePostEffects = original.spatializePostEffects;
			dest.spread = original.spread;
			dest.time = original.time;
			dest.timeSamples = original.timeSamples;
			dest.velocityUpdateMode = original.velocityUpdateMode;
			dest.volume = original.volume;
		}

		public static void CreateScanNodeOnObject(GameObject obj, int nodeType, int minRange, int maxRange, string headerText)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("ScanNode", new Type[2]
			{
				typeof(ScanNodeProperties),
				typeof(BoxCollider)
			})
			{
				layer = LayerMask.NameToLayer("ScanNode")
			};
			val.transform.parent = obj.transform;
			val.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
			ScanNodeProperties component = val.GetComponent<ScanNodeProperties>();
			component.nodeType = nodeType;
			component.minRange = minRange;
			component.maxRange = maxRange;
			component.headerText = headerText;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BlindBirdStringEnjoyersImprovements";

		public const string PLUGIN_NAME = "BlindBirdStringEnjoyersImprovements";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace BlindBirdStringEnjoyersImprovements.Patches
{
	public static class EntranceTeleportPatch
	{
		[HarmonyPatch(typeof(EntranceTeleport), "TeleportPlayer")]
		[HarmonyPostfix]
		private static void TeleportPlayer(EntranceTeleport __instance)
		{
			if (__instance.entranceId != 0 && __instance.isEntranceToBuilding)
			{
				FlipPlayer(__instance, GameNetworkManager.Instance.localPlayerController);
			}
		}

		[HarmonyPatch(typeof(EntranceTeleport), "TeleportPlayerClientRpc")]
		[HarmonyPostfix]
		private static void TeleportPlayerClientRpc(EntranceTeleport __instance, int playerObj)
		{
			if (__instance.entranceId != 0 && __instance.isEntranceToBuilding)
			{
				PlayerControllerB val = __instance.playersManager.allPlayerScripts[playerObj];
				if (!((NetworkBehaviour)val).IsOwner)
				{
					FlipPlayer(__instance, val);
				}
			}
		}

		private static void FlipPlayer(EntranceTeleport instance, PlayerControllerB player)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			Vector3 eulerAngles = instance.exitPoint.eulerAngles;
			((Component)player).transform.rotation = Quaternion.Euler(eulerAngles.x, eulerAngles.y + 180f, eulerAngles.z);
		}
	}
	public static class GameNetworkManagerPatch
	{
		private static IReadOnlyList<NetworkPrefab> AllPrefabs => NetworkManager.Singleton.NetworkConfig.Prefabs.Prefabs;

		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		[HarmonyPostfix]
		private static void Start(GameNetworkManager __instance)
		{
			NetworkPrefab val = ((IEnumerable<NetworkPrefab>)AllPrefabs).FirstOrDefault((Func<NetworkPrefab, bool>)((NetworkPrefab p) => ((Object)p.Prefab).name == "FancyLamp"));
			if (val != null)
			{
				Plugin.LogSource.LogInfo((object)"Adding ToggleableFancyLamp behavior to FancyLamp prefab.");
				PhysicsProp component = val.Prefab.GetComponent<PhysicsProp>();
				FancyLampToggle fancyLampToggle = val.Prefab.AddComponent<FancyLampToggle>();
				Utils.CopyGrabbablePrefab<FancyLampToggle>((GrabbableObject)(object)component, fancyLampToggle);
				((GrabbableObject)fancyLampToggle).itemProperties.toolTips = new string[1] { "Toggle Light : [LMB]" };
				((GrabbableObject)fancyLampToggle).itemProperties.syncUseFunction = true;
				Object.Destroy((Object)(object)component);
				NetworkPrefab? obj = ((IEnumerable<NetworkPrefab>)AllPrefabs).FirstOrDefault((Func<NetworkPrefab, bool>)((NetworkPrefab p) => ((Object)p.Prefab).name == "FlashlightItem"));
				FlashlightItem val2 = ((obj != null) ? obj.Prefab.GetComponent<FlashlightItem>() : null);
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2.flashlightAudio != (Object)null && val2.flashlightClips != null && val2.flashlightClips.Length != 0)
				{
					AudioSource dest = val.Prefab.AddComponent<AudioSource>();
					Utils.CopyAudioSource(val2.flashlightAudio, dest);
					fancyLampToggle.AudioClips = val2.flashlightClips;
				}
			}
		}
	}
	public class GrabbableObjectPatch
	{
		private static HashSet<GrabbableObject> _itemsToKeepInPlace = new HashSet<GrabbableObject>();

		[HarmonyPatch(typeof(GrabbableObject), "Start")]
		[HarmonyPrefix]
		private static void Start_Pre(GrabbableObject __instance)
		{
			List<Type> obj = new List<Type>
			{
				typeof(BoomboxItem),
				typeof(ExtensionLadderItem),
				typeof(FlashlightItem),
				typeof(JetpackItem),
				typeof(LockPicker),
				typeof(RadarBoosterItem),
				typeof(Shovel),
				typeof(SprayPaintItem),
				typeof(StunGrenadeItem),
				typeof(TetraChemicalItem),
				typeof(WalkieTalkie),
				typeof(PatcherTool)
			};
			if (!__instance.itemProperties.isScrap)
			{
				ScanNodeProperties componentInChildren = ((Component)__instance).GetComponentInChildren<ScanNodeProperties>();
				if (componentInChildren != null)
				{
					string subText = componentInChildren.subText;
					__instance.SetScrapValue(0);
					if (subText != null && !subText.ToLower().StartsWith("value"))
					{
						componentInChildren.subText = subText;
					}
				}
				else
				{
					__instance.scrapValue = 0;
				}
			}
			if (obj.Contains(((object)__instance).GetType()) && (Object)(object)((Component)__instance).GetComponentInChildren<ScanNodeProperties>() == (Object)null)
			{
				Utils.CreateScanNodeOnObject(((Component)__instance).gameObject, 0, 1, 13, __instance.itemProperties.itemName);
			}
			if (__instance.isInShipRoom && __instance.isInElevator && __instance.scrapPersistedThroughRounds)
			{
				_itemsToKeepInPlace.Add(__instance);
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "Start")]
		[HarmonyPostfix]
		private static void Start_Post(GrabbableObject __instance)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (_itemsToKeepInPlace.Contains(__instance))
			{
				__instance.fallTime = 1f;
				__instance.reachedFloorTarget = false;
				__instance.targetFloorPosition = ((Component)__instance).transform.localPosition;
				_itemsToKeepInPlace.Remove(__instance);
			}
		}
	}
	public static class HUDManagerPatch
	{
		[HarmonyPatch(typeof(HUDManager), "Update")]
		[HarmonyPostfix]
		private static void Update(HUDManager __instance)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < __instance.itemSlotIcons.Length; i++)
			{
				StartOfRound instance = StartOfRound.Instance;
				GrabbableObject val = ((instance != null) ? instance.localPlayerController.ItemSlots[i] : null);
				if ((Object)(object)val == (Object)null || (Object)(object)StormyWeatherPatch.Instance == (Object)null)
				{
					((Graphic)__instance.itemSlotIcons[i]).color = Color.white;
					continue;
				}
				Traverse obj = Traverse.Create((object)StormyWeatherPatch.Instance);
				GameObject val2 = ((obj != null) ? obj.Field("setStaticToObject").GetValue<GameObject>() : null);
				GrabbableObject val3 = null;
				try
				{
					if ((Object)(object)val2 != (Object)null)
					{
						val3 = val2.GetComponent<GrabbableObject>();
					}
				}
				catch
				{
				}
				StartOfRound instance2 = StartOfRound.Instance;
				if (instance2 != null && !instance2.localPlayerController.isInsideFactory)
				{
					StartOfRound instance3 = StartOfRound.Instance;
					if (instance3 != null && !instance3.localPlayerController.isInElevator && (Object)(object)val3 != (Object)null && (Object)(object)val3 == (Object)(object)val)
					{
						((Graphic)__instance.itemSlotIcons[i]).color = Color.red;
						continue;
					}
				}
				if ((Object)(object)StormyWeatherPatch.Instance != (Object)null && val.itemProperties.isConductiveMetal)
				{
					((Graphic)__instance.itemSlotIcons[i]).color = Color.yellow;
				}
				else
				{
					((Graphic)__instance.itemSlotIcons[i]).color = Color.white;
				}
			}
		}
	}
	public static class PreInitSceneScriptPatch
	{
		[HarmonyPatch(typeof(PreInitSceneScript), "SkipToFinalSetting")]
		[HarmonyPrefix]
		private static bool SkipToFinalSetting(PreInitSceneScript __instance)
		{
			__instance.ChooseLaunchOption(true);
			return false;
		}
	}
	public static class ShipTeleporterPatch
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> beamUpPlayer(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 5; i < list.Count; i++)
			{
				if (!(list[i].opcode == OpCodes.Callvirt) || !((list[i].operand as MethodInfo)?.Name == "DropAllHeldItems") || !(list[i - 5].opcode == OpCodes.Ldfld) || !((list[i - 5].operand as FieldInfo)?.Name == "deadBody"))
				{
					continue;
				}
				CodeInstruction item = Transpilers.EmitDelegate<Action>((Action)delegate
				{
					GrabbableObject val = StartOfRound.Instance?.mapScreen?.targetedPlayer?.deadBody?.grabBodyObject;
					if ((Object)(object)val != (Object)null)
					{
						StartOfRound.Instance.mapScreen.targetedPlayer.SetItemInElevator(true, true, val);
					}
				});
				list.Insert(i + 1, item);
			}
			return list.AsEnumerable();
		}
	}
	public static class StormyWeatherPatch
	{
		public static StormyWeather Instance { get; private set; }

		[HarmonyPatch(typeof(StormyWeather), "OnEnable")]
		[HarmonyPostfix]
		private static void OnEnable(StormyWeather __instance)
		{
			if ((Object)(object)Instance != (Object)(object)__instance)
			{
				Instance = __instance;
			}
		}

		[HarmonyPatch(typeof(StormyWeather), "OnDisable")]
		[HarmonyPostfix]
		private static void OnDisable()
		{
			Instance = null;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}