Decompiled source of AutoItemMultiplier v0.1.2

plugins/com.github.LengSword.AutoItemMultiplier.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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.LengSword.AutoItemMultiplier")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.2.0")]
[assembly: AssemblyInformationalVersion("0.1.2+3cef984b8f740c35bbf02d1e1a9f2d7ee603fa09")]
[assembly: AssemblyProduct("com.github.LengSword.AutoItemMultiplier")]
[assembly: AssemblyTitle("AutoItemMultiplier")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.2.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.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;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace AutoItemMultiplier
{
	[BepInPlugin("com.github.LengSword.AutoItemMultiplier", "AutoItemMultiplier", "0.1.2")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Id = "com.github.LengSword.AutoItemMultiplier";

		internal static ManualLogSource Logger { get; private set; }

		public static string Name => "AutoItemMultiplier";

		public static string Version => "0.1.2";

		private void Awake()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)("Plugin " + Name + " is loaded!"));
			PluginConfig.Initialize(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger);
			Harmony val = new Harmony("com.github.LengSword.AutoItemMultiplier");
			val.PatchAll();
		}

		internal static bool IsMultiplierEnabled(Spawner spawner)
		{
			string name = ((object)spawner).GetType().Name;
			switch (name)
			{
			case "Luggage":
				return PluginConfig.EnableLuggageConfig.Value;
			case "RespawnChest":
				return PluginConfig.EnableRespawnChestConfig.Value;
			case "BerryBush":
				return PluginConfig.EnableBerryBushConfig.Value;
			case "BerryVine":
				return PluginConfig.EnableBerryVineConfig.Value;
			case "GroundPlaceSpawner":
				return PluginConfig.EnableGroundSpawnerConfig.Value;
			default:
				Logger.LogInfo((object)("[" + name + "] Unknown spawner type, multiplier disabled"));
				return false;
			}
		}
	}
	public static class PluginConfig
	{
		internal static ConfigEntry<bool> EnableMultiplierConfig { get; private set; }

		internal static ConfigEntry<float> ItemMultiplierIncrementConfig { get; private set; }

		internal static ConfigEntry<bool> EnableLuggageConfig { get; private set; }

		internal static ConfigEntry<bool> EnableRespawnChestConfig { get; private set; }

		internal static ConfigEntry<bool> EnableBerryBushConfig { get; private set; }

		internal static ConfigEntry<bool> EnableBerryVineConfig { get; private set; }

		internal static ConfigEntry<bool> EnableGroundSpawnerConfig { get; private set; }

		public static void Initialize(ConfigFile config, ManualLogSource logger)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			EnableMultiplierConfig = config.Bind<bool>("General", "EnableMultiplier", true, "Enable item multiplier");
			ItemMultiplierIncrementConfig = config.Bind<float>("General", "ItemMultiplierIncrement", 0.25f, new ConfigDescription("Item spawn multiplier increment when players count > 4 (0.25 = +0.25x/player items )", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			EnableLuggageConfig = config.Bind<bool>("SpawnerTypes", "EnableLuggage", true, "Enable multiplier for Luggage (chests)");
			EnableRespawnChestConfig = config.Bind<bool>("SpawnerTypes", "EnableRespawnChest", false, "Enable multiplier for RespawnChest");
			EnableBerryBushConfig = config.Bind<bool>("SpawnerTypes", "EnableBerryBush", false, "Enable multiplier for BerryBush");
			EnableBerryVineConfig = config.Bind<bool>("SpawnerTypes", "EnableBerryVine", false, "Enable multiplier for BerryVine");
			EnableGroundSpawnerConfig = config.Bind<bool>("SpawnerTypes", "EnableGroundSpawner", false, "Enable multiplier for GroundPlaceSpawner");
			logger.LogInfo((object)"Plugin Config Loaded.");
		}
	}
	[HarmonyPatch(typeof(Spawner), "SpawnItems")]
	public static class SpawnerPatch
	{
		public static bool Prefix(Spawner __instance, List<Transform> spawnSpots, ref List<PhotonView> __result)
		{
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			__result = new List<PhotonView>();
			if (!PhotonNetwork.IsMasterClient)
			{
				return false;
			}
			if (spawnSpots.Count == 0)
			{
				return false;
			}
			if (!PluginConfig.EnableMultiplierConfig.Value || PhotonNetwork.CurrentRoom.PlayerCount <= 4 || PluginConfig.ItemMultiplierIncrementConfig.Value == 0f)
			{
				Plugin.Logger.LogInfo((object)"1x multiplier, using original spawn");
				return true;
			}
			string name = ((object)__instance).GetType().Name;
			if (!Plugin.IsMultiplierEnabled(__instance))
			{
				Plugin.Logger.LogInfo((object)("[" + name + "] Multiplier disabled, using original spawn"));
				return true;
			}
			float num = 1f + (float)Mathf.Max(0, PhotonNetwork.CurrentRoom.PlayerCount - 4) * PluginConfig.ItemMultiplierIncrementConfig.Value;
			Plugin.Logger.LogInfo((object)$"[{name}] Multiplier enabled, applying {num}x");
			MethodInfo method = typeof(Spawner).GetMethod("GetObjectsToSpawn", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field = typeof(Spawner).GetField("canRepeatSpawns", BindingFlags.Instance | BindingFlags.Public);
			FieldInfo field2 = typeof(Spawner).GetField("centerItemsVisually", BindingFlags.Instance | BindingFlags.Public);
			FieldInfo field3 = typeof(Spawner).GetField("spawnUpTowardsTarget", BindingFlags.Instance | BindingFlags.Public);
			bool flag = (bool)field.GetValue(__instance);
			bool flag2 = (bool)field2.GetValue(__instance);
			Transform val = (Transform)field3.GetValue(__instance);
			int num2 = Mathf.RoundToInt((float)spawnSpots.Count * num);
			Plugin.Logger.LogInfo((object)$"[{name}] Spawning {num2} items (original: {spawnSpots.Count}, multiplier: {num}x)");
			List<GameObject> list = (List<GameObject>)method.Invoke(__instance, new object[2] { num2, flag });
			for (int i = 0; i < num2 && i < list.Count; i++)
			{
				if ((Object)(object)list[i] != (Object)null)
				{
					Transform val2 = spawnSpots[i % spawnSpots.Count];
					val2.rotation = Quaternion.Euler(val2.eulerAngles + new Vector3(90f, 0f, 0f));
					Vector3 val3 = val2.position;
					if (i >= spawnSpots.Count)
					{
						val3 += new Vector3(Random.Range(-0.5f, 0.5f), Random.Range(0f, 0.2f), Random.Range(-0.5f, 0.5f));
					}
					Item component = PhotonNetwork.InstantiateItemRoom(((Object)list[i]).name, val3, val2.rotation).GetComponent<Item>();
					__result.Add(((Component)component).GetComponent<PhotonView>());
					if ((Object)(object)val != (Object)null)
					{
						Transform transform = ((Component)component).transform;
						Vector3 val4 = val.position - ((Component)component).transform.position;
						transform.up = ((Vector3)(ref val4)).normalized;
					}
					if (flag2)
					{
						Vector3 val5 = val2.position - component.Center();
						Transform transform2 = ((Component)component).transform;
						transform2.position += val5;
					}
					if ((Object)(object)component != (Object)null)
					{
						((Component)component).GetComponent<PhotonView>().RPC("SetKinematicRPC", (RpcTarget)3, new object[3]
						{
							true,
							((Component)component).transform.position,
							((Component)component).transform.rotation
						});
					}
				}
			}
			return false;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}