Decompiled source of ScavRewardNerf v1.0.1

plugins/ScavRewardNerf/ScavRewardNerf.dll

Decompiled 10 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 Microsoft.CodeAnalysis;
using RoR2;
using ScavSackNerf;
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(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("ScavRewardNerf")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ScavRewardNerf")]
[assembly: AssemblyTitle("ScavRewardNerf")]
[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 ScavSackNerf
{
	internal class ScavRewardNerfConfig
	{
		public static ConfigEntry<ushort> commonWeight;

		public static ConfigEntry<ushort> uncommonWeight;

		public static ConfigEntry<ushort> leginderWeight;

		public static ConfigEntry<short> maxItems;

		public static ConfigEntry<bool> disabledPreLoop;

		public static void Setup(ConfigFile config)
		{
			commonWeight = config.Bind<ushort>("Rarity Weights", "Common", (ushort)79, (ConfigDescription)null);
			uncommonWeight = config.Bind<ushort>("Rarity Weights", "Uncommon", (ushort)20, (ConfigDescription)null);
			leginderWeight = config.Bind<ushort>("Rarity Weights", "Legendary", (ushort)1, (ConfigDescription)null);
			maxItems = config.Bind<short>("Misc", "Maximum Items Per Stage", (short)5, "The maximum number of scavengers that can drop an item each stage\r\nSet to 0 to prevent scavengers from dropping anything\r\nSet to a negative number to remove the limit");
			disabledPreLoop = config.Bind<bool>("Misc", "Disabled Before Looping", true, "Should scavengers drop vanilla scavenger sacks containing the full 10 items before looping?\r\nTrue by default since I think it's cool that you can get extra items on Sundered Grove to give you a boost on slow runs");
		}
	}
}
namespace ExamplePlugin
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInPlugin("acats.ScavRewardNerf", "ScavRewardNerf", "1.0.1")]
	public class ScavRewardNerf : BaseUnityPlugin
	{
		public const string PluginGUID = "acats.ScavRewardNerf";

		public const string PluginAuthor = "acats";

		public const string PluginName = "ScavRewardNerf";

		public const string PluginVersion = "1.0.1";

		private Xoroshiro128Plus itemDropRandom;

		private int scavsKilled;

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			ScavRewardNerfConfig.Setup(((BaseUnityPlugin)this).Config);
		}

		private void OnEnable()
		{
			GlobalEventManager.onCharacterDeathGlobal += OnDeath;
			Stage.onServerStageBegin += ServerStageBegin;
		}

		private void OnDisable()
		{
			GlobalEventManager.onCharacterDeathGlobal -= OnDeath;
			Stage.onServerStageBegin -= ServerStageBegin;
		}

		private void ServerStageBegin(Stage stage)
		{
			scavsKilled = 0;
			if (Enabled())
			{
				stage.scavPackDroppedServer = true;
			}
		}

		private ushort CommonWeight()
		{
			return ScavRewardNerfConfig.commonWeight.Value;
		}

		private ushort UncommonWeight()
		{
			return ScavRewardNerfConfig.uncommonWeight.Value;
		}

		private ushort LeginderWeight()
		{
			return ScavRewardNerfConfig.leginderWeight.Value;
		}

		private bool Enabled()
		{
			return !ScavRewardNerfConfig.disabledPreLoop.Value || Run.instance.stageClearCount >= 5;
		}

		private int MaxDropsAllowed()
		{
			return ScavRewardNerfConfig.maxItems.Value;
		}

		private bool ActuallyKilled(DamageReport damageReport)
		{
			CharacterMaster victimMaster = damageReport.victimMaster;
			Inventory val = ((victimMaster != null) ? victimMaster.inventory : null);
			return Object.op_Implicit((Object)(object)val) && val.GetItemCount(Items.ExtraLife) == 0 && !Object.op_Implicit((Object)(object)damageReport.victimMaster.minionOwnership.ownerMaster) && (!Object.op_Implicit((Object)(object)damageReport.victimBody) || !Object.op_Implicit((Object)(object)damageReport.victimBody.healthComponent) || !damageReport.victimBody.healthComponent.alive);
		}

		private void OnDeath(DamageReport damageReport)
		{
			//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_00be: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			if (Enabled() && MaxDropsAllowed() != 0 && (MaxDropsAllowed() <= 0 || scavsKilled < MaxDropsAllowed()) && !(((Object)damageReport.victim).name != "ScavBody(Clone)") && ActuallyKilled(damageReport))
			{
				scavsKilled++;
				if (itemDropRandom == null)
				{
					itemDropRandom = new Xoroshiro128Plus(Run.instance.seed);
				}
				List<PickupIndex> randomTier = GetRandomTier();
				PickupIndex val = randomTier[itemDropRandom.RangeInt(0, randomTier.Count)];
				PickupDropletController.CreatePickupDroplet(val, damageReport.victimBody.corePosition, Vector3.zero);
			}
		}

		private List<PickupIndex> GetRandomTier()
		{
			int num = itemDropRandom.RangeInt(0, CommonWeight() + UncommonWeight() + LeginderWeight());
			if (num < CommonWeight())
			{
				return Run.instance.availableTier1DropList;
			}
			if (num < CommonWeight() + UncommonWeight())
			{
				return Run.instance.availableTier2DropList;
			}
			return Run.instance.availableTier3DropList;
		}
	}
}