Decompiled source of OdinHatesLitter v1.0.2

plugins/OdinHatesLitter.dll

Decompiled 20 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("OdinHatesLitter")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OdinHatesLitter")]
[assembly: AssemblyTitle("OdinHatesLitter")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 OdinHatesLitter
{
	[HarmonyPatch(typeof(InventoryGui), "OnDropOutside")]
	internal static class InventoryGridDropPatch
	{
		private static void Prefix()
		{
			Debug.Log((object)"[OdinHatesLitter] NEW PATCH OnDropOutside ONLY");
			Plugin.TryShowLitterMessage(null, 1);
		}
	}
	internal static class LitterMessages
	{
		private static readonly string[] CommonMessages = new string[20]
		{
			"Odin frowns upon your carelessness.", "The forest remembers what you leave behind.", "Another offering to the wilderness.", "The greydwarfs appreciate your donation.", "A raven quietly records your littering.", "The wilds gain another forgotten treasure.", "Hugin has questions about your disposal methods.", "The spirits of Valheim are unimpressed.", "The ground accepts your offering.", "Your junk now belongs to the forest.",
			"The ravens have noticed.", "A neck considers this a generous gift.", "The wilderness accepts your poor decision.", "Valheim grows slightly messier.", "The Allfather expected better.", "Somewhere, a greydwarf is thrilled.", "The land itself sighs.", "That belongs to the wilds now.", "The forest takes custody of your belongings.", "Even the draugr know better."
		};

		private static readonly string[] RareMessages = new string[5] { "Odin has witnessed your crime.", "The gods will remember this.", "Hugin files an official complaint.", "The ravens have seen enough.", "Your littering has been noted in the halls of Valhalla." };

		internal static string GetRandomMessage()
		{
			if (Random.Range(0, 100) < 5)
			{
				return RareMessages[Random.Range(0, RareMessages.Length)];
			}
			return CommonMessages[Random.Range(0, CommonMessages.Length)];
		}
	}
	[BepInPlugin("Dova.OdinHatesLitter", "OdinHatesLitter", "1.0.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string ModGuid = "Dova.OdinHatesLitter";

		public const string ModName = "OdinHatesLitter";

		public const string ModVersion = "1.0.0";

		internal static ConfigEntry<bool> EnableMod;

		internal static ConfigEntry<int> TriggerChance;

		internal static ConfigEntry<bool> CenterMessage;

		internal static ConfigEntry<bool> DebugLogging;

		private Harmony _harmony = null;

		private void Awake()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			EnableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableMod", true, "Enable or disable OdinHatesLitter.");
			TriggerChance = ((BaseUnityPlugin)this).Config.Bind<int>("General", "TriggerChance", 10, "Percent chance that a message appears when you intentionally drop an item. 0-100.");
			CenterMessage = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "CenterMessage", true, "If true, shows center-screen messages. If false, shows top-left messages.");
			DebugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DebugLogging", false, "Enable debug logs for testing item drop detection.");
			_harmony = new Harmony("Dova.OdinHatesLitter");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"OdinHatesLitter 1.0.0 loaded.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		internal static void TryShowLitterMessage(ItemData item, int amount)
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			if (!EnableMod.Value)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				int num = Mathf.Clamp(TriggerChance.Value, 0, 100);
				if (num > 0 && Random.Range(0, 100) < num)
				{
					string randomMessage = LitterMessages.GetRandomMessage();
					MessageType val = (MessageType)((!CenterMessage.Value) ? 1 : 2);
					((Character)localPlayer).Message(val, randomMessage, 0, (Sprite)null);
				}
			}
		}
	}
}