Decompiled source of ScarletTrash v1.0.0

ScarletTrash.dll

Decompiled 2 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 System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using ScarletCore;
using ScarletCore.Data;
using ScarletCore.Services;
using ScarletCore.Systems;
using ScarletCore.Utils;
using Unity.Collections;
using Unity.Entities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ScarletTrash")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ScarletTrash")]
[assembly: AssemblyTitle("ScarletTrash")]
[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 ScarletTrash
{
	[HarmonyPatch]
	internal static class InventoryPatch
	{
		public static Dictionary<Entity, ActionId> RunningActions = new Dictionary<Entity, ActionId>();

		private static readonly float DelaySeconds = 15f;

		[HarmonyPatch(typeof(ReactToInventoryChangedSystem), "OnUpdate")]
		[HarmonyPrefix]
		public static void Prefix(ReactToInventoryChangedSystem __instance)
		{
			//IL_0013: 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_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_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)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			if (!GameSystems.Initialized)
			{
				return;
			}
			EntityQuery _query_2096870026_ = __instance.__query_2096870026_0;
			NativeArray<Entity> val = ((EntityQuery)(ref _query_2096870026_)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				Enumerator<Entity> enumerator = val.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					InventoryChangedEvent val2 = ECSExtensions.Read<InventoryChangedEvent>(current);
					Entity inventory = val2.InventoryEntity;
					if (!ECSExtensions.Has<NameableInteractable>(inventory) && ECSExtensions.Has<Attach>(inventory))
					{
						inventory = ECSExtensions.Read<Attach>(inventory).Parent;
					}
					if (!ECSExtensions.Has<NameableInteractable>(inventory))
					{
						continue;
					}
					NameableInteractable val3 = ECSExtensions.Read<NameableInteractable>(inventory);
					if (!Regex.IsMatch(((FixedString64Bytes)(ref val3.Name)).Value, "\\bSTrash\\b"))
					{
						continue;
					}
					if (RunningActions.TryGetValue(inventory, out var value))
					{
						ActionScheduler.CancelAction(value);
						RunningActions.Remove(inventory);
					}
					RunningActions.Add(inventory, ActionScheduler.Delayed((Action)delegate
					{
						//IL_0002: 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_0012: Unknown result type (might be due to invalid IL or missing references)
						if (ECSExtensions.Exists(inventory))
						{
							InventoryService.ClearInventory(inventory);
						}
						RunningActions.Remove(inventory);
					}, DelaySeconds));
				}
			}
			finally
			{
				val.Dispose();
			}
		}

		[HarmonyPatch(typeof(NameableInteractableSystem), "OnUpdate")]
		[HarmonyPrefix]
		public static void Prefix(NameableInteractableSystem __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: 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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			EntityQuery renameQuery = __instance._RenameQuery;
			NativeArray<Entity> val = ((EntityQuery)(ref renameQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			NativeParallelHashMap<NetworkId, Entity> networkIdToEntityMap = GameSystems.NetworkIdSystem._NetworkIdLookupMap._NetworkIdToEntityMap;
			Enumerator<Entity> enumerator = val.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				RenameInteractable val2 = ECSExtensions.Read<RenameInteractable>(current);
				if (Regex.IsMatch(((FixedString64Bytes)(ref val2.NewName)).Value, "\\bSTrash\\b"))
				{
					FromCharacter val3 = ECSExtensions.Read<FromCharacter>(current);
					if (ECSExtensions.IsPlayer(val3.Character))
					{
						PlayerData playerData = PlayerDataExtensions.GetPlayerData(val3.Character);
						playerData.SendMessage(RichTextFormatter.FormatError("**~⚠~ Container renamed to trash bin! ~⚠~**"));
						playerData.SendMessage(RichTextFormatter.FormatError("Items placed inside will be ~permanently deleted~ after ~15 seconds~ of no activity."));
						playerData.SendMessage(RichTextFormatter.FormatError("Timer resets each time you move items. There is ~no undo~!"));
					}
				}
			}
		}
	}
	[BepInPlugin("ScarletTrash", "ScarletTrash", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		private static Harmony _harmony;

		public static Harmony Harmony => _harmony;

		public static Plugin Instance { get; private set; }

		public static ManualLogSource LogInstance { get; private set; }

		public override void Load()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			Instance = this;
			LogInstance = ((BasePlugin)this).Log;
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("ScarletTrash");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
			_harmony = new Harmony("ScarletTrash");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
		}

		public override bool Unload()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ScarletTrash";

		public const string PLUGIN_NAME = "ScarletTrash";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}