Decompiled source of CrimsonDropRate v0.2.1

CrimsonDropRate.dll

Decompiled a month 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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Bloodstone.API;
using CrimsonDropRate.Configs;
using CrimsonDropRate.Systems;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using ProjectM;
using ProjectM.Shared;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("CrimsonDropRate")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Modifies the item group drop rate, not the item quantity drop.")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyInformationalVersion("0.2.1+1.Branch.master.Sha.cdeae81adb4d92151c4f036c2a4f4a831e5fb489")]
[assembly: AssemblyProduct("CrimsonDropRate")]
[assembly: AssemblyTitle("CrimsonDropRate")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.1.0")]
[module: UnverifiableCode]
namespace CrimsonDropRate
{
	[BepInPlugin("CrimsonDropRate", "CrimsonDropRate", "0.2.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		public static ManualLogSource Logger;

		public override void Load()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			if (VWorld.IsServer)
			{
				Logger = ((BasePlugin)this).Log;
				DropRateConfig.Initialize(((BasePlugin)this).Config);
				_harmony = new Harmony("CrimsonDropRate");
				_harmony.PatchAll(Assembly.GetExecutingAssembly());
				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>("CrimsonDropRate");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.2.1");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
				}
				log.LogInfo(val);
			}
		}

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

		public const string PLUGIN_NAME = "CrimsonDropRate";

		public const string PLUGIN_VERSION = "0.2.1";
	}
}
namespace CrimsonDropRate.Systems
{
	internal static class DropRateSystem
	{
		internal static void ChangeDropRate()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_0087: 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_009c: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			if (DropRateConfig.DropRateModifier.Value == 1f)
			{
				return;
			}
			ManualLogSource logger = Plugin.Logger;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(37, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Changing drop rate values. Modifier: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(DropRateConfig.DropRateModifier.Value);
			}
			logger.LogInfo(val);
			PrefabCollectionSystem existingSystemManaged = VWorld.Server.GetExistingSystemManaged<PrefabCollectionSystem>();
			foreach (DropTableBuffer entitiesDropTable in GetEntitiesDropTables())
			{
				Entity val2 = ((PrefabLookupMap)(ref ((PrefabCollectionSystem_Base)existingSystemManaged).PrefabLookupMap))[entitiesDropTable.DropTableGuid];
				EntityManager entityManager = VWorld.Server.EntityManager;
				if (!((EntityManager)(ref entityManager)).HasComponent<DropTableDataBuffer>(val2))
				{
					continue;
				}
				entityManager = VWorld.Server.EntityManager;
				DynamicBuffer<DropTableDataBuffer> buffer = ((EntityManager)(ref entityManager)).GetBuffer<DropTableDataBuffer>(val2, false);
				List<DropTableDataBuffer> list = new List<DropTableDataBuffer>();
				Enumerator<DropTableDataBuffer> enumerator2 = buffer.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					DropTableDataBuffer current2 = enumerator2.Current;
					list.Add(new DropTableDataBuffer
					{
						DropRate = Math.Min(1f, current2.DropRate * DropRateConfig.DropRateModifier.Value),
						ItemGuid = current2.ItemGuid,
						ItemType = current2.ItemType,
						Quantity = current2.Quantity
					});
				}
				buffer.RemoveRange(0, buffer.Length);
				foreach (DropTableDataBuffer item in list)
				{
					buffer.Add(item);
				}
			}
			ManualLogSource logger2 = Plugin.Logger;
			val = new BepInExInfoLogInterpolatedStringHandler(37, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Drop rate values changed successfully");
			}
			logger2.LogInfo(val);
		}

		private static IList<DropTableBuffer> GetEntitiesDropTables()
		{
			//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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_00a6: 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)
			List<DropTableBuffer> list = new List<DropTableBuffer>();
			EntityManager entityManager = VWorld.Server.EntityManager;
			EntityQueryDesc[] array = new EntityQueryDesc[1];
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<DropTableBuffer>() });
			val.Options = (EntityQueryOptions)195;
			array[0] = val;
			EntityQuery val2 = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)array);
			Enumerator<Entity> enumerator = ((EntityQuery)(ref val2)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)).GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				entityManager = VWorld.Server.EntityManager;
				Enumerator<DropTableBuffer> enumerator2 = ((EntityManager)(ref entityManager)).GetBuffer<DropTableBuffer>(current, false).GetEnumerator();
				while (enumerator2.MoveNext())
				{
					DropTableBuffer dropTable = enumerator2.Current;
					if (!list.Any((DropTableBuffer r) => r.DropTableGuid == dropTable.DropTableGuid))
					{
						list.Add(dropTable);
					}
				}
			}
			return list;
		}
	}
}
namespace CrimsonDropRate.Hooks
{
	[HarmonyPatch]
	internal static class LoadPersistanceHook
	{
		[HarmonyPatch(typeof(LoadPersistenceSystemV2), "SetLoadState")]
		[HarmonyPrefix]
		private static void SetLoadState(State loadState)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			try
			{
				if ((int)loadState == 4)
				{
					DropRateSystem.ChangeDropRate();
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)ex.Message);
			}
		}
	}
}
namespace CrimsonDropRate.Configs
{
	internal static class DropRateConfig
	{
		internal static ConfigEntry<float> DropRateModifier { get; private set; }

		internal static void Initialize(ConfigFile config)
		{
			DropRateModifier = config.Bind<float>("DropRateConfig", "DropRateModifier", 1f, "Drop rate modifer value");
		}
	}
}