Decompiled source of mod5 Modpack v1.1.0

plugins/BuyableShotgun.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("BuyableShotgun")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("Copyright © 2023 MegaPiggy")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f4271793e57a966e00668122ac278845cc79146b")]
[assembly: AssemblyProduct("BuyableShotgun")]
[assembly: AssemblyTitle("BuyableShotgun")]
[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 BuyableShotgun
{
	[BepInDependency("evaisa.lethallib", "0.13.2")]
	[BepInPlugin("MegaPiggy.BuyableShotgun", "Buyable Shotgun", "1.0.4")]
	public class BuyableShotgun : BaseUnityPlugin
	{
		private const string modGUID = "MegaPiggy.BuyableShotgun";

		private const string modName = "Buyable Shotgun";

		private const string modVersion = "1.0.4";

		private readonly Harmony harmony = new Harmony("MegaPiggy.BuyableShotgun");

		private static BuyableShotgun Instance;

		private ConfigEntry<int> ShotgunPriceConfig;

		private static Dictionary<string, TerminalNode> infoNodes = new Dictionary<string, TerminalNode>();

		private static ManualLogSource LoggerInstance => ((BaseUnityPlugin)Instance).Logger;

		public List<Item> AllItems => Resources.FindObjectsOfTypeAll<Item>().Concat(Object.FindObjectsByType<Item>((FindObjectsInactive)1, (FindObjectsSortMode)1)).ToList();

		public Item Shotgun => ((IEnumerable<Item>)AllItems).FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name.Equals("Shotgun")));

		public Item ShotgunClone { get; private set; }

		public int ShotgunPrice => ShotgunPriceConfig.Value;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			harmony.PatchAll();
			ShotgunPriceConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Prices", "ShotgunPrice", 700, "Credits needed to buy shotgun");
			SceneManager.sceneLoaded += OnSceneLoaded;
			ShotgunClone = MakeNonScrap(ShotgunPrice);
			AddToShop();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Buyable Shotgun is loaded with version 1.0.4!");
		}

		private Item MakeNonScrap(int price)
		{
			//IL_00cb: 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)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			Item val = ScriptableObject.CreateInstance<Item>();
			Object.DontDestroyOnLoad((Object)(object)val);
			((Object)val).name = "Error";
			val.itemName = "Error";
			val.itemId = 6624;
			val.isScrap = false;
			val.creditsWorth = price;
			val.canBeGrabbedBeforeGameStart = true;
			val.automaticallySetUsingPower = false;
			val.batteryUsage = 300f;
			val.canBeInspected = false;
			val.isDefensiveWeapon = true;
			val.saveItemVariable = true;
			val.syncGrabFunction = false;
			val.twoHandedAnimation = true;
			val.verticalOffset = 0.25f;
			GameObject val2 = NetworkPrefabs.CreateNetworkPrefab("Cube");
			GameObject val3 = GameObject.CreatePrimitive((PrimitiveType)3);
			val3.transform.SetParent(val2.transform, false);
			((Renderer)val3.GetComponent<MeshRenderer>()).sharedMaterial.shader = Shader.Find("HDRP/Lit");
			val2.AddComponent<BoxCollider>().size = Vector3.one * 2f;
			val2.AddComponent<AudioSource>();
			PhysicsProp val4 = val2.AddComponent<PhysicsProp>();
			((GrabbableObject)val4).itemProperties = val;
			((GrabbableObject)val4).grabbable = true;
			val.spawnPrefab = val2;
			val2.tag = "PhysicsProp";
			val2.layer = LayerMask.NameToLayer("Props");
			val3.layer = LayerMask.NameToLayer("Props");
			try
			{
				GameObject val5 = Object.Instantiate<GameObject>(Items.scanNodePrefab, val2.transform);
				((Object)val5).name = "ScanNode";
				val5.transform.localPosition = new Vector3(0f, 0f, 0f);
				Transform transform = val5.transform;
				transform.localScale *= 2f;
				ScanNodeProperties component = val5.GetComponent<ScanNodeProperties>();
				component.nodeType = 1;
				component.headerText = "Error";
				component.subText = "A mod is incompatible with Buyable Shotgun";
			}
			catch (Exception ex)
			{
				LoggerInstance.LogError((object)ex.ToString());
			}
			val2.transform.localScale = Vector3.one / 2f;
			return val;
		}

		private void CloneNonScrap(Item original, Item clone, int price)
		{
			Object.DontDestroyOnLoad((Object)(object)original.spawnPrefab);
			CopyFields(original, clone);
			((Object)clone).name = "Buyable" + ((Object)original).name;
			clone.creditsWorth = price;
		}

		public static void CopyFields(Item source, Item destination)
		{
			FieldInfo[] fields = typeof(Item).GetFields();
			FieldInfo[] array = fields;
			foreach (FieldInfo fieldInfo in array)
			{
				fieldInfo.SetValue(destination, fieldInfo.GetValue(source));
			}
		}

		private TerminalNode CreateInfoNode(string name, string description)
		{
			if (infoNodes.ContainsKey(name))
			{
				return infoNodes[name];
			}
			TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>();
			Object.DontDestroyOnLoad((Object)(object)val);
			val.clearPreviousText = true;
			((Object)val).name = name + "InfoNode";
			val.displayText = description + "\n\n";
			infoNodes.Add(name, val);
			return val;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			LoggerInstance.LogInfo((object)("Scene \"" + ((Scene)(ref scene)).name + "\" loaded with " + ((object)(LoadSceneMode)(ref mode)).ToString() + " mode."));
			if (!((Object)(object)Shotgun == (Object)null))
			{
				CloneNonScrap(Shotgun, ShotgunClone, ShotgunPrice);
			}
		}

		private void AddToShop()
		{
			Item shotgunClone = ShotgunClone;
			int shotgunPrice = ShotgunPrice;
			Items.RegisterShopItem(shotgunClone, (TerminalNode)null, (TerminalNode)null, CreateInfoNode("Shotgun", "Nutcracker's shotgun. Can hold 2 shells. Recommended to keep safety on while not using or it might shoot randomly."), shotgunPrice);
			LoggerInstance.LogInfo((object)$"Shotgun added to Shop for {ShotgunPrice} credits");
		}
	}
}

plugins/NameplateTweaks.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dissonance;
using GameNetcodeStuff;
using HarmonyLib;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("NameplateTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Configurable client-side mod for player username billboards. Speaking indicators, better visibility, etc.")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyInformationalVersion("1.0.6")]
[assembly: AssemblyProduct("NameplateTweaks")]
[assembly: AssemblyTitle("NameplateTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.6.0")]
[module: UnverifiableCode]
namespace NameplateTweaks;

[BepInPlugin("taffyko.NameplateTweaks", "NameplateTweaks", "1.0.6")]
public class Plugin : BaseUnityPlugin
{
	public const string modGUID = "taffyko.NameplateTweaks";

	public const string modName = "NameplateTweaks";

	public const string modVersion = "1.0.6";

	public static ConfigEntry<bool> ConfigEnableSpeakingIndicator;

	public static ConfigEntry<bool> ConfigVariableSpeakingIndicatorOpacity;

	public static ConfigEntry<bool> ConfigSpeakingIndicatorAlwaysVisible;

	public static ConfigEntry<float> ConfigNameplateScale;

	public static ConfigEntry<float> ConfigNameplateVisibilityDistance;

	public static ConfigEntry<bool> ConfigNameplateScaleWithDistance;

	public static ManualLogSource log;

	private readonly Harmony harmony = new Harmony("taffyko.NameplateTweaks");

	public static Vector3? OriginalNameplateScale = new Vector3(-0.0025f, 0.0025f, 0.0025f);

	private void Awake()
	{
		log = Logger.CreateLogSource("NameplateTweaks");
		log.LogInfo((object)"Loading taffyko.NameplateTweaks");
		ConfigEnableSpeakingIndicator = ((BaseUnityPlugin)this).Config.Bind<bool>("Speaking Indicator", "EnableSpeakingIndicator", true, "Enable a voice-activity speaking indicator above player nameplates");
		ConfigVariableSpeakingIndicatorOpacity = ((BaseUnityPlugin)this).Config.Bind<bool>("Speaking Indicator", "VariableSpeakingIndicatorOpacity", true, "Speaking indicator opacity changes depending on volume");
		ConfigSpeakingIndicatorAlwaysVisible = ((BaseUnityPlugin)this).Config.Bind<bool>("Speaking Indicator", "SpeakingIndicatorAlwaysVisible", true, "Display speaking indicators even when the nameplate is hidden");
		ConfigNameplateScale = ((BaseUnityPlugin)this).Config.Bind<float>("Nameplate", "NameplateScale", 1.5f, "Nameplate size multiplier (1.0 is the vanilla size)");
		ConfigNameplateVisibilityDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Nameplate", "NameplateVisibilityDistance", 20f, "Distance from the camera within which nameplates are visible (0.0 reverts to vanilla behavior). The length of the ship is ~20 units, for reference");
		ConfigNameplateScaleWithDistance = ((BaseUnityPlugin)this).Config.Bind<bool>("Nameplate", "NameplateScaleWithDistance", false, "Scale nameplates so that they retain their apparent size as they get further away");
		harmony.PatchAll(Assembly.GetExecutingAssembly());
	}

	private void OnDestroy()
	{
	}
}
public class SpeakingIndicator : MonoBehaviour
{
	public PlayerControllerB player;

	public Canvas canvas;

	public GameObject canvasItem;

	public CanvasGroup canvasItemAlpha;

	public static Dictionary<PlayerControllerB, SpeakingIndicator> speakingIndicators = new Dictionary<PlayerControllerB, SpeakingIndicator>();

	private static Texture2D speakingIconTexture = null;

	public static Texture2D GetSpeakingIconTexture()
	{
		if ((Object)(object)speakingIconTexture != (Object)null)
		{
			return speakingIconTexture;
		}
		return GameObject.Find("PTTIcon").GetComponent<Image>().sprite.texture;
	}

	public static SpeakingIndicator GetSpeakingIndicator(PlayerControllerB player)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		speakingIndicators.TryGetValue(player, out var value);
		if ((Object)(object)value == (Object)null)
		{
			GameObject val = new GameObject("SpeakingIndicator");
			val.SetActive(false);
			value = val.AddComponent<SpeakingIndicator>();
			value.player = player;
			((Component)value).transform.SetParent(((Component)player).transform, false);
			speakingIndicators.Add(player, value);
			val.SetActive(true);
		}
		return value;
	}

	public void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		canvasItem = new GameObject("SpeakingIndicatorCanvasItem");
		canvasItem.transform.SetParent(player.usernameBillboard, false);
		canvasItem.AddComponent<CanvasRenderer>();
		canvasItemAlpha = canvasItem.AddComponent<CanvasGroup>();
		canvasItemAlpha.alpha = 0f;
		canvasItem.transform.localPosition = new Vector3(0f, 60f, 0f);
		canvasItem.AddComponent<Image>().sprite = Sprite.Create(GetSpeakingIconTexture(), new Rect(0f, 0f, 260f, 280f), new Vector2(130f, 140f), 100f);
	}

	private float lexp(float a, float b, float t)
	{
		return Mathf.Lerp(a, b, Mathf.Exp(0f - t));
	}

	public void Update()
	{
		VoicePlayerState voicePlayerState = player.voicePlayerState;
		if (voicePlayerState != null)
		{
			float num = Mathf.Clamp(voicePlayerState.Amplitude * 35f, 0f, 1f);
			if (Plugin.ConfigVariableSpeakingIndicatorOpacity.Value)
			{
				if (num > 0.01f)
				{
					canvasItemAlpha.alpha = lexp(canvasItemAlpha.alpha, num, Time.deltaTime * 100f);
				}
				else
				{
					canvasItemAlpha.alpha = lexp(canvasItemAlpha.alpha, num, Time.deltaTime * 50f);
				}
			}
			else if (num > 0.05f)
			{
				canvasItemAlpha.alpha = 1f;
			}
			else if (num < 0.01f)
			{
				canvasItemAlpha.alpha = 0f;
			}
		}
		if (!Plugin.ConfigSpeakingIndicatorAlwaysVisible.Value)
		{
			canvasItemAlpha.alpha = Math.Min(canvasItemAlpha.alpha, player.usernameAlpha.alpha);
		}
		if (((NetworkBehaviour)player).IsOwner)
		{
			canvasItemAlpha.alpha = 0f;
		}
		if (!Plugin.ConfigEnableSpeakingIndicator.Value)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}

	public void OnDestroy()
	{
		speakingIndicators.Remove(player);
		Object.Destroy((Object)(object)canvasItem);
	}
}
[HarmonyPatch]
public class Patches
{
	[HarmonyPatch(typeof(HUDManager), "UpdateSpectateBoxSpeakerIcons")]
	[HarmonyPostfix]
	public static void UpdateSpectateBoxSpeakerIcons(HUDManager __instance, ref Dictionary<Animator, PlayerControllerB> ___spectatingPlayerBoxes)
	{
		foreach (var (val3, val4) in ___spectatingPlayerBoxes)
		{
			if (!((NetworkBehaviour)val4).IsOwner)
			{
				continue;
			}
			if (!(IngamePlayerSettings.Instance?.settings?.pushToTalk).GetValueOrDefault())
			{
				break;
			}
			PlayerInput playerInput = IngamePlayerSettings.Instance.playerInput;
			bool? obj;
			if (playerInput == null)
			{
				obj = null;
			}
			else
			{
				InputActionAsset actions = playerInput.actions;
				if (actions == null)
				{
					obj = null;
				}
				else
				{
					InputAction obj2 = actions.FindAction("VoiceButton", false);
					obj = ((obj2 != null) ? new bool?(obj2.IsPressed()) : null);
				}
			}
			bool? flag = obj;
			bool valueOrDefault = flag.GetValueOrDefault();
			val3.SetBool("speaking", valueOrDefault);
			break;
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "Update")]
	[HarmonyPostfix]
	public static void PlayerUpdate(PlayerControllerB __instance)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: 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)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		((TMP_Text)__instance.usernameBillboardText).text = __instance.playerUsername;
		if (Plugin.ConfigEnableSpeakingIndicator.Value)
		{
			SpeakingIndicator.GetSpeakingIndicator(__instance);
		}
		__instance.usernameBillboard.position = new Vector3(__instance.playerGlobalHead.position.x, __instance.playerGlobalHead.position.y + 0.55f, __instance.playerGlobalHead.position.z);
		if ((Object)(object)__instance == (Object)(object)StartOfRound.Instance?.localPlayerController)
		{
			__instance.usernameAlpha.alpha = 0f;
		}
		else if ((Object)(object)StartOfRound.Instance?.localPlayerController != (Object)null)
		{
			float num = Vector3.Distance(((Component)StartOfRound.Instance.localPlayerController.gameplayCamera).transform.position, __instance.usernameBillboard.position);
			if (num < Plugin.ConfigNameplateVisibilityDistance.Value)
			{
				__instance.usernameAlpha.alpha = 1f;
				((Behaviour)__instance.usernameBillboardText).enabled = true;
				((Component)__instance.usernameCanvas).gameObject.SetActive(true);
			}
			float num2 = 1f;
			if (Plugin.ConfigNameplateScaleWithDistance.Value)
			{
				num2 = 1f + Math.Max(0f, (num - 4f) * 0.11f);
			}
			__instance.usernameBillboard.localScale = Plugin.OriginalNameplateScale.Value * Plugin.ConfigNameplateScale.Value * num2;
		}
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "NameplateTweaks";

	public const string PLUGIN_NAME = "NameplateTweaks";

	public const string PLUGIN_VERSION = "1.0.6";
}