Decompiled source of DeathNotDrop v1.0.1

DeathNotDrop.dll

Decompiled 3 months ago
using System;
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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Scenes;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DeathNotDrop")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Death not drop anything")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: AssemblyInformationalVersion("1.0.1+57cc277c6bc295567e284b0a1a592f59c3520607")]
[assembly: AssemblyProduct("DeathNotDrop")]
[assembly: AssemblyTitle("DeathNotDrop")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DeathNotDrop
{
	[BepInPlugin("DeathNotDrop", "DeathNotDrop", "1.0.1")]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		public static Plugin Instance { get; private set; }

		public override void Load()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			Instance = this;
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.1");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded successfully");
			}
			log.LogInfo(val);
			_harmony = new Harmony("DeathNotDrop");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
		}

		public override bool Unload()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}

		public void OnGameInitialized()
		{
			if (Application.productName != "VRisingServer")
			{
				((BasePlugin)this).Log.LogError((object)"This is SERVER ONLY plugin!");
				return;
			}
			World world = GetWorld("Server");
			if (world == null)
			{
				((BasePlugin)this).Log.LogError((object)"Failed to get Server world");
				return;
			}
			PrefabCollectionSystem existingSystemManaged = world.GetExistingSystemManaged<PrefabCollectionSystem>();
			if (existingSystemManaged != null && existingSystemManaged.SpawnableNameToPrefabGuidDictionary.Count == 0)
			{
				((BasePlugin)this).Log.LogError((object)"Game data not loaded yet");
				return;
			}
			((BasePlugin)this).Log.LogInfo((object)"Game initialization complete");
			SetAllItemsBloodBound();
		}

		private void SetAllItemsBloodBound()
		{
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				World world = GetWorld("Server");
				if (world == null)
				{
					((BasePlugin)this).Log.LogError((object)"Server world not available");
					return;
				}
				_ = world.EntityManager;
				GameDataSystem existingSystemManaged = world.GetExistingSystemManaged<GameDataSystem>();
				PrefabCollectionSystem existingSystemManaged2 = world.GetExistingSystemManaged<PrefabCollectionSystem>();
				if (existingSystemManaged == null || existingSystemManaged2 == null)
				{
					((BasePlugin)this).Log.LogError((object)"Required systems not found");
					return;
				}
				int num = 0;
				NativeParallelHashMap<PrefabGUID, ItemData> itemHashLookupMap = existingSystemManaged.ItemHashLookupMap;
				NativeArray<PrefabGUID> keyArray = itemHashLookupMap.GetKeyArray(AllocatorHandle.op_Implicit((Allocator)2));
				BepInExInfoLogInterpolatedStringHandler val4;
				try
				{
					ItemData val2 = default(ItemData);
					for (int i = 0; i < keyArray.Length; i++)
					{
						PrefabGUID val = keyArray[i];
						if (!itemHashLookupMap.TryGetValue(val, ref val2))
						{
							continue;
						}
						string itemName = GetItemName(existingSystemManaged2, val);
						if (itemName == null || !itemName.StartsWith("Item_"))
						{
							continue;
						}
						ItemCategory val3 = (ItemCategory)(val2.ItemCategory | 8);
						if (val3 != val2.ItemCategory)
						{
							val2.ItemCategory = val3;
							itemHashLookupMap[val] = val2;
							num++;
							ManualLogSource log = ((BasePlugin)this).Log;
							val4 = new BepInExInfoLogInterpolatedStringHandler(17, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Modified prefab: ");
								((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(itemName);
							}
							log.LogInfo(val4);
						}
					}
				}
				finally
				{
					keyArray.Dispose();
				}
				ManualLogSource log2 = ((BasePlugin)this).Log;
				val4 = new BepInExInfoLogInterpolatedStringHandler(28, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Completed: Modified ");
					((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(num);
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" prefabs");
				}
				log2.LogInfo(val4);
			}
			catch (Exception ex)
			{
				ManualLogSource log3 = ((BasePlugin)this).Log;
				BepInExErrorLogInterpolatedStringHandler val5 = new BepInExErrorLogInterpolatedStringHandler(7, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Error: ");
					((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<Exception>(ex);
				}
				log3.LogError(val5);
			}
		}

		private string GetItemName(PrefabCollectionSystem prefabSystem, PrefabGUID guid)
		{
			//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_001e: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<string, PrefabGUID> enumerator = prefabSystem.SpawnableNameToPrefabGuidDictionary.GetEnumerator();
			while (enumerator.MoveNext())
			{
				KeyValuePair<string, PrefabGUID> current = enumerator.Current;
				PrefabGUID value = current.Value;
				if (((PrefabGUID)(ref value)).Equals(guid))
				{
					return current.Key;
				}
			}
			return null;
		}

		private World GetWorld(string name)
		{
			Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
			while (enumerator.MoveNext())
			{
				World current = enumerator.Current;
				if (current.Name == name)
				{
					return current;
				}
			}
			return null;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "DeathNotDrop";

		public const string PLUGIN_NAME = "DeathNotDrop";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}
namespace DeathNotDrop.Hooks
{
	[HarmonyPatch(typeof(SceneSectionStreamingSystem), "ShutdownAsynchrnonousStreamingSupport")]
	public static class LoadPatch
	{
		private static bool _initialized;

		public static void Postfix()
		{
			if (!_initialized && Plugin.Instance != null)
			{
				Plugin.Instance.OnGameInitialized();
				_initialized = true;
			}
		}
	}
}