Decompiled source of SniffinFarts v1.0.1

plugins/SniffinFarts.dll

Decompiled 8 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[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("SniffinFarts")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SniffinFarts")]
[assembly: AssemblyTitle("SniffinFarts")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
[BepInPlugin("com.nilaier.sniffinfarts", "Sniffin' Farts", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
	private Harmony harmony;

	private static float lastHealTime;

	private static Coroutine healingCoroutine;

	private void Awake()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		harmony = new Harmony("com.nilaier.sniffinfarts");
		harmony.PatchAll(typeof(Plugin));
		PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
		Debug.Log((object)"Plugin SniffinFarts is loaded!");
	}

	[HarmonyPatch(typeof(PufferAI), "ShakeTailClientRpc")]
	[HarmonyPostfix]
	private static void PufferAI_ShakeTailClientRpc_Postfix(PufferAI __instance)
	{
		Debug.Log((object)"PufferAI_ShakeTailClientRpc_Postfix called");
		((MonoBehaviour)__instance).StartCoroutine(StartHealingCoroutineWithDelay(__instance, 0.6f));
	}

	private static IEnumerator StartHealingCoroutineWithDelay(PufferAI pufferAI, float delay)
	{
		yield return (object)new WaitForSeconds(delay);
		((MonoBehaviour)pufferAI).StartCoroutine(HealingCoroutine(pufferAI));
	}

	private static IEnumerator HealingCoroutine(PufferAI pufferAI)
	{
		while (true)
		{
			PlayerControllerB localPlayer = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)localPlayer != (Object)null && localPlayer.health < 100)
			{
				GameObject smokePrefab = GameObject.Find(((Object)pufferAI.smokePrefab).name + "(Clone)");
				if ((Object)(object)smokePrefab != (Object)null)
				{
					float distance = Vector3.Distance(((Component)localPlayer).transform.position, smokePrefab.transform.position);
					if (distance <= PluginConfig.HealingRange.Value && Time.time - lastHealTime >= PluginConfig.HealingInterval.Value)
					{
						float healAmount = PluginConfig.HealingAmount.Value;
						int roundedHealAmount = Mathf.RoundToInt(healAmount);
						localPlayer.health = Mathf.Min(localPlayer.health + roundedHealAmount, 100);
						Debug.Log((object)$"Player healed by {roundedHealAmount}. New health: {localPlayer.health}");
						localPlayer.increasingDrunknessThisFrame = true;
						localPlayer.drunkness += PluginConfig.DrunknessIncreasePerHeal.Value;
						Debug.Log((object)$"Player's drunkness increased by {PluginConfig.DrunknessIncreasePerHeal.Value}. New drunkness: {localPlayer.drunkness}");
						if ((Object)(object)HUDManager.Instance != (Object)null && (Object)(object)HUDManager.Instance.drunknessFilter != (Object)null)
						{
							Volume drunknessFilter = HUDManager.Instance.drunknessFilter;
							drunknessFilter.weight += PluginConfig.DrunknessFilterIncreasePerHeal.Value;
							Debug.Log((object)$"Drunkness filter intensity increased by {PluginConfig.DrunknessFilterIncreasePerHeal.Value}. New intensity: {HUDManager.Instance.drunknessFilter.weight}");
						}
						lastHealTime = Time.time;
					}
				}
			}
			yield return (object)new WaitForSeconds(PluginConfig.HealingInterval.Value);
		}
	}
}
public static class PluginConfig
{
	public static ConfigEntry<float> HealingAmount;

	public static ConfigEntry<float> HealingInterval;

	public static ConfigEntry<float> HealingRange;

	public static ConfigEntry<float> DrunknessIncreasePerHeal;

	public static ConfigEntry<float> DrunknessFilterIncreasePerHeal;

	public static void BindConfig(ConfigFile config)
	{
		HealingAmount = config.Bind<float>("General", "HealingAmount", 1f, "The amount of health to heal the player per interval");
		HealingInterval = config.Bind<float>("General", "HealingInterval", 0.3f, "The interval (in seconds) between each heal");
		HealingRange = config.Bind<float>("General", "HealingRange", 10f, "The range within which the player gets healed");
		DrunknessIncreasePerHeal = config.Bind<float>("General", "DrunknessIncreasePerHeal", 0.05f, "The amount to increase the player's drunkness per heal");
		DrunknessFilterIncreasePerHeal = config.Bind<float>("General", "DrunknessFilterIncreasePerHeal", 0.01f, "The amount to increase the drunkness filter intensity per heal");
	}
}