Decompiled source of greatestmod v0.1.1

plugins/GreatestmodPlugin/R0B0.GreatestMod.dll

Decompiled a day 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 GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using R0B0.GreatestMod.Monobehaviours;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;

[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("R0B0.GreatestMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1")]
[assembly: AssemblyProduct("GreatestMod")]
[assembly: AssemblyTitle("R0B0.GreatestMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.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 R0B0.GreatestMod
{
	[BepInPlugin("R0B0.GreatestMod", "GreatestMod", "0.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static AssetBundle MyCustomAssets;

		public static AudioClip carLights;

		public static Plugin 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;
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			MyCustomAssets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "greatestmod"));
			if ((Object)(object)MyCustomAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			carLights = MyCustomAssets.LoadAsset<AudioClip>("Assets/GreatestMod/CompanyCruiserToy/Cruiser_HeadlightsOn.ogg");
			int num = 30;
			Item val = MyCustomAssets.LoadAsset<Item>("Assets/GreatestMod/CompanyCruiserToy/CompanyCruiserToy.asset");
			GameObject val2 = MyCustomAssets.LoadAsset<GameObject>("Assets/GreatestMod/CompanyCruiserToy/ToyCar.prefab");
			((GrabbableObject)val2.AddComponent<CompanyCruiserToy>()).itemProperties = val;
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Items.RegisterScrap(val, num, (LevelTypes)4096);
			Item val3 = MyCustomAssets.LoadAsset<Item>("Assets/GreatestMod/PortableCharger/PortableCharger.asset");
			NetworkPrefabs.RegisterNetworkPrefab(val3.spawnPrefab);
			int num2 = 100;
			TerminalNode val4 = MyCustomAssets.LoadAsset<TerminalNode>("Assets/GreatestMod/TerminalNodes/iTerminalNode.asset");
			Items.RegisterShopItem(val3, (TerminalNode)null, (TerminalNode)null, val4, num2);
			Patch();
			Logger.LogInfo((object)"R0B0.GreatestMod v0.0.1 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("R0B0.GreatestMod");
			}
			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 = "R0B0.GreatestMod";

		public const string PLUGIN_NAME = "GreatestMod";

		public const string PLUGIN_VERSION = "0.0.1";
	}
}
namespace R0B0.GreatestMod.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB), "Update")]
	internal class ExhaustionPatch
	{
		[HarmonyPostfix]
		private static void PlayerControllerB_Update(PlayerControllerB __instance)
		{
			if (!__instance.isExhausted)
			{
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "Interact_performed")]
	internal class PlayerInteractionPatch
	{
		[HarmonyPostfix]
		private static void PlayerControllerB_Interact_performed(PlayerControllerB __instance, CallbackContext context)
		{
			if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerDead && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject))
			{
				if (!StartOfRound.Instance.overrideSpectateCamera && (Object)(object)__instance.spectatedPlayerScript != (Object)null && !__instance.spectatedPlayerScript.isPlayerDead)
				{
					__instance.SpectateNextPlayer(false);
				}
			}
			else
			{
				if (((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer) || !((CallbackContext)(ref context)).performed || __instance.timeSinceSwitchingSlots < 0.2f || __instance.inSpecialMenu)
				{
					return;
				}
				ShipBuildModeManager.Instance.CancelBuildMode(true);
				if (!__instance.isGrabbingObjectAnimation && !__instance.isTypingChat && !__instance.inTerminalMenu && !__instance.throwingObject && !__instance.IsInspectingItem && !((Object)(object)__instance.inAnimationWithEnemy != (Object)null) && !__instance.jetpackControls && !__instance.disablingJetpackControls && !StartOfRound.Instance.suckingPlayersOutOfShip)
				{
					if (!__instance.activatingItem && !__instance.waitingToDropItem)
					{
						__instance.BeginGrabObject();
					}
					if (!((Object)(object)__instance.hoveringOverTrigger == (Object)null) && !__instance.hoveringOverTrigger.holdInteraction && (!__instance.isHoldingObject || __instance.hoveringOverTrigger.oneHandedItemAllowed) && (!__instance.twoHanded || (__instance.hoveringOverTrigger.twoHandedItemAllowed && !__instance.hoveringOverTrigger.specialCharacterAnimation) || (__instance.hoveringOverTrigger.twoHandedItemAllowed && __instance.hoveringOverTrigger.hoverTip == "Charge item : [LMB]")) && __instance.InteractTriggerUseConditionsMet())
					{
						__instance.hoveringOverTrigger.Interact(__instance.thisPlayerBody);
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(ItemCharger))]
	internal class PowerOutletStun
	{
		private const int DAMAGEAMOUNT = 50;

		private const float BODYTHROWMULTIPLIER = 0.5f;

		private const int DAMAGEDISTRIBUTION = 3;

		[HarmonyPatch("ChargeItem")]
		[HarmonyPrefix]
		private static void ItemCharger_ChargeItem(ItemCharger __instance)
		{
			Plugin.Logger.LogDebug((object)"------------- Charged item!! ------------------------");
			GrabbableObject currentlyHeldObjectServer = GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer;
			if (!((Object)(object)currentlyHeldObjectServer == (Object)null) && (currentlyHeldObjectServer.itemProperties.requiresBattery || currentlyHeldObjectServer.itemProperties.isConductiveMetal))
			{
				__instance.PlayChargeItemEffectServerRpc((int)GameNetworkManager.Instance.localPlayerController.playerClientId);
				if (__instance.chargeItemCoroutine != null)
				{
					((MonoBehaviour)__instance).StopCoroutine(__instance.chargeItemCoroutine);
				}
				if (currentlyHeldObjectServer.itemProperties.requiresBattery)
				{
					__instance.chargeItemCoroutine = ((MonoBehaviour)__instance).StartCoroutine(__instance.chargeItemDelayed(currentlyHeldObjectServer));
				}
				else if (currentlyHeldObjectServer.itemProperties.isConductiveMetal && !currentlyHeldObjectServer.itemProperties.twoHanded)
				{
					__instance.chargeItemCoroutine = ((MonoBehaviour)__instance).StartCoroutine(chargeItemDelayedButBetter(currentlyHeldObjectServer, __instance.zapAudio, __instance.chargeStationAnimator, 1f));
				}
				else if (currentlyHeldObjectServer.itemProperties.isConductiveMetal && currentlyHeldObjectServer.itemProperties.twoHanded)
				{
					__instance.chargeItemCoroutine = ((MonoBehaviour)__instance).StartCoroutine(chargeItemDelayedButBetter(currentlyHeldObjectServer, __instance.zapAudio, __instance.chargeStationAnimator, 2f));
				}
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void ItemCharger_Update(ItemCharger __instance)
		{
			if (__instance.updateInterval == 0f)
			{
				__instance.updateInterval = 0f;
				if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
				{
					__instance.triggerScript.interactable = (Object)(object)GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer != (Object)null && (GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer.itemProperties.isConductiveMetal || GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer.itemProperties.requiresBattery);
				}
			}
		}

		private static IEnumerator chargeItemDelayedButBetter(GrabbableObject itemToCharge, AudioSource zapAudio, Animator chargeStationAnimator, float damageMultiplier)
		{
			zapAudio.Play();
			yield return (object)new WaitForSeconds(0.6f);
			chargeStationAnimator.SetTrigger("zap");
			if ((Object)(object)itemToCharge != (Object)null)
			{
				for (int i = 0; i < 3; i++)
				{
					GameNetworkManager.Instance.localPlayerController.DamagePlayer(Mathf.RoundToInt(16f * damageMultiplier), true, true, (CauseOfDeath)11, 0, false, default(Vector3));
					yield return (object)new WaitForSeconds(0.1f);
				}
			}
		}
	}
}
namespace R0B0.GreatestMod.Monobehaviours
{
	public class CompanyCruiserToy : GrabbableObject
	{
		[Space(15f)]
		public int flashlightInterferenceLevel;

		public static int globalFlashlightInterferenceLevel;

		public bool changeMaterial = true;

		public Light flashlightBulb { get; set; }

		public Light flashlightBulbGlow { get; set; }

		public AudioSource flashlightAudio { get; set; }

		public AudioClip[] flashlightClips { get; set; }

		public AudioClip outOfBatteriesClip { get; set; }

		public AudioClip flashlightFlicker { get; set; }

		public Material bulbLight { get; set; }

		public Material bulbDark { get; set; }

		public MeshRenderer flashlightMesh { get; set; }

		public int flashlightTypeID { get; set; }

		private float initialIntensity { get; set; }

		private PlayerControllerB previousPlayerHeldBy { get; set; }

		public void Awake()
		{
			base.grabbable = true;
			base.isInFactory = true;
			base.grabbableToEnemies = true;
			changeMaterial = false;
			flashlightBulb = ((Component)this).GetComponentsInChildren<Light>()[0];
			flashlightBulbGlow = ((Component)this).GetComponentsInChildren<Light>()[1];
			flashlightAudio = ((Component)this).GetComponent<AudioSource>();
			flashlightClips = (AudioClip[])(object)new AudioClip[1];
			flashlightClips[0] = Plugin.carLights;
			base.insertedBattery.empty = false;
			base.insertedBattery.charge = 100f;
		}

		public override void Start()
		{
			((GrabbableObject)this).Start();
			initialIntensity = flashlightBulb.intensity;
		}

		public override void UseUpBatteries()
		{
			((GrabbableObject)this).UseUpBatteries();
			SwitchFlashlight(on: false);
		}

		public override void PocketItem()
		{
			Plugin.Logger.LogError((object)"Truck pocketed");
			if (!((NetworkBehaviour)this).IsOwner)
			{
				((GrabbableObject)this).PocketItem();
				return;
			}
			if ((Object)(object)previousPlayerHeldBy != (Object)null)
			{
				((Behaviour)flashlightBulb).enabled = false;
				((Behaviour)flashlightBulbGlow).enabled = false;
				if (base.isBeingUsed && ((Object)(object)previousPlayerHeldBy.ItemSlots[previousPlayerHeldBy.currentItemSlot] == (Object)null || previousPlayerHeldBy.ItemSlots[previousPlayerHeldBy.currentItemSlot].itemProperties.itemId != 1 || previousPlayerHeldBy.ItemSlots[previousPlayerHeldBy.currentItemSlot].itemProperties.itemId != 6))
				{
					previousPlayerHeldBy.pocketedFlashlight = (GrabbableObject)(object)this;
					PocketFlashlightServerRpc(stillUsingFlashlight: true);
				}
				else
				{
					base.isBeingUsed = false;
					((Behaviour)flashlightBulbGlow).enabled = false;
					SwitchFlashlight(on: false);
					PocketFlashlightServerRpc();
				}
			}
			else
			{
				Debug.Log((object)"Could not find what player was holding this flashlight item");
			}
			((GrabbableObject)this).PocketItem();
		}

		[ServerRpc]
		public void PocketFlashlightServerRpc(bool stillUsingFlashlight = false)
		{
			PocketFlashlightClientRpc(stillUsingFlashlight);
		}

		[ClientRpc]
		public void PocketFlashlightClientRpc(bool stillUsingFlashlight)
		{
			if (((NetworkBehaviour)this).IsOwner)
			{
				return;
			}
			((Behaviour)flashlightBulb).enabled = false;
			((Behaviour)flashlightBulbGlow).enabled = false;
			if (stillUsingFlashlight)
			{
				if (!((Object)(object)previousPlayerHeldBy == (Object)null))
				{
					previousPlayerHeldBy.pocketedFlashlight = (GrabbableObject)(object)this;
				}
			}
			else
			{
				base.isBeingUsed = false;
				((Behaviour)flashlightBulbGlow).enabled = false;
				SwitchFlashlight(on: false);
			}
		}

		public override void DiscardItem()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).DiscardItem();
			RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, 25f, 0.95f, 0, base.isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
		}

		public override void EquipItem()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			previousPlayerHeldBy = base.playerHeldBy;
			SwitchFlashlight(on: true);
			RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, 15f, 0.65f, 0, base.isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
			((GrabbableObject)this).EquipItem();
		}

		public void SwitchFlashlight(bool on)
		{
			base.isBeingUsed = on;
			if (!((NetworkBehaviour)this).IsOwner)
			{
				Debug.Log((object)$"Flashlight click. playerheldby null?: {(Object)(object)base.playerHeldBy != (Object)null}");
				Debug.Log((object)$"Flashlight being disabled or enabled: {on}");
				Plugin.Logger.LogInfo((object)"If not owner or something?");
			}
			else
			{
				((Behaviour)flashlightBulb).enabled = on;
				((Behaviour)flashlightBulbGlow).enabled = on;
			}
			if (changeMaterial)
			{
				Material[] sharedMaterials = ((Renderer)flashlightMesh).sharedMaterials;
				if (on)
				{
					sharedMaterials[1] = bulbLight;
				}
				else
				{
					sharedMaterials[1] = bulbDark;
				}
				((Renderer)flashlightMesh).sharedMaterials = sharedMaterials;
			}
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			int num = ((flashlightInterferenceLevel <= globalFlashlightInterferenceLevel) ? globalFlashlightInterferenceLevel : flashlightInterferenceLevel);
			if (num >= 2)
			{
				flashlightBulb.intensity = 0f;
			}
			else if (num == 1)
			{
				flashlightBulb.intensity = Random.Range(0f, 200f);
			}
			else
			{
				flashlightBulb.intensity = initialIntensity;
			}
		}
	}
	public class PortableItemCharger : NetworkBehaviour
	{
		private const float CHARGEBATTERYAMOUNT = 0.1f;

		public PortableItemChargerItem itemThing;

		public InteractTrigger triggerScript;

		public Animator chargeStationAnimator;

		private Coroutine chargeItemCoroutine;

		public AudioSource zapAudio;

		private float updateInterval;

		public void ChargeItem()
		{
			GrabbableObject currentlyHeldObjectServer = GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer;
			if (!((Object)(object)currentlyHeldObjectServer == (Object)null) && currentlyHeldObjectServer.itemProperties.requiresBattery && ((GrabbableObject)itemThing).insertedBattery.charge >= 0.1f)
			{
				PlayChargeItemEffectServerRpc((int)GameNetworkManager.Instance.localPlayerController.playerClientId);
				if (chargeItemCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(chargeItemCoroutine);
				}
				chargeItemCoroutine = ((MonoBehaviour)this).StartCoroutine(chargeItemDelayed(currentlyHeldObjectServer));
			}
		}

		private void Update()
		{
			if ((Object)(object)NetworkManager.Singleton == (Object)null)
			{
				return;
			}
			if (updateInterval > 1f)
			{
				updateInterval = 0f;
				if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
				{
					if (((GrabbableObject)itemThing).heldByPlayerOnServer)
					{
						triggerScript.interactable = false;
						triggerScript.disabledHoverTip = "This item is currently not in use. Please put the item down to use it";
					}
					else if (((GrabbableObject)itemThing).insertedBattery.charge < 0.1f)
					{
						triggerScript.interactable = false;
						triggerScript.disabledHoverTip = "(It's empty. Why would I even try)";
					}
					else if ((Object)(object)GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer == (Object)(object)itemThing)
					{
						triggerScript.interactable = false;
						triggerScript.disabledHoverTip = "You can't charge the battery with itself >:(";
					}
					else
					{
						triggerScript.disabledHoverTip = "(Requires battery-powered item)";
						triggerScript.interactable = (Object)(object)GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer != (Object)null && GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer.itemProperties.requiresBattery;
					}
				}
			}
			else
			{
				updateInterval += Time.deltaTime;
			}
		}

		private IEnumerator chargeItemDelayed(GrabbableObject itemToCharge)
		{
			zapAudio.Play();
			yield return (object)new WaitForSeconds(0.75f);
			chargeStationAnimator.SetTrigger("zap");
			if ((Object)(object)itemToCharge != (Object)null)
			{
				itemToCharge.insertedBattery = new Battery(false, 1f);
				itemToCharge.SyncBatteryServerRpc(100);
				Battery insertedBattery = ((GrabbableObject)itemThing).insertedBattery;
				insertedBattery.charge -= 0.1f;
				Debug.Log((object)Mathf.RoundToInt(((GrabbableObject)itemThing).insertedBattery.charge * 10f));
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void PlayChargeItemEffectServerRpc(int playerChargingItem)
		{
			PlayChargeItemEffectClientRpc(playerChargingItem);
		}

		[ClientRpc]
		public void PlayChargeItemEffectClientRpc(int playerChargingItem)
		{
			if (!((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null) && (int)GameNetworkManager.Instance.localPlayerController.playerClientId != playerChargingItem)
			{
				if (chargeItemCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(chargeItemCoroutine);
				}
				chargeItemCoroutine = ((MonoBehaviour)this).StartCoroutine(chargeItemDelayed(null));
			}
		}
	}
	public class PortableItemChargerItem : GrabbableObject
	{
		public Collider ItemChargerInterractCollider;

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if (base.heldByPlayerOnServer)
			{
				ItemChargerInterractCollider.enabled = false;
			}
			else
			{
				ItemChargerInterractCollider.enabled = true;
			}
			if ((double)base.insertedBattery.charge < 0.1 && (double)base.insertedBattery.charge > 0.01 && !base.insertedBattery.empty)
			{
				base.insertedBattery.charge = 0.1f;
			}
			else if (base.insertedBattery.charge == 0f)
			{
				base.insertedBattery.empty = true;
			}
		}
	}
}