Decompiled source of AdaptiveMoneyBags v1.0.0

AdaptiveMoneyBags.dll

Decompiled 5 days 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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("voprossoss")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AdaptiveMoneyBags")]
[assembly: AssemblyTitle("AdaptiveMoneyBags")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 AdaptiveMoneyBags
{
	[BepInPlugin("voprossoss.AdaptiveMoneyBags", "AdaptiveMoneyBags", "1.0.0")]
	public class AdaptiveMoneyBags : BaseUnityPlugin
	{
		internal static AdaptiveMoneyBags Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
	[HarmonyPatch(typeof(ExtractionPoint), "SpawnTaxReturn")]
	public static class SpawnTaxReturnPatch
	{
		private const int SingleBagMaxValue = 13000;

		private const int VanillaMaxValue = 10000;

		private const int MinSplitBagValue = 8000;

		private const int AverageSplitBagValue = 10000;

		private const int MaxBagsNormal = 5;

		private const int MaxBagsHuge = 7;

		private const int HugeSurplusThreshold = 200000;

		private const float ValueVariation = 0.3f;

		private const float MinScale = 0.25f;

		private const float LowMidScale = 0.55f;

		private const float LowMidValue = 2000f;

		private const float VanillaScale = 1f;

		private const float MaxEnlargedScale = 1.3f;

		private const float ScaleMinValue = 150f;

		private const float ScaleMaxValue = 10000f;

		private const float SpawnRadius = 0.55f;

		private const float SpawnHeightStep = 0.18f;

		private static bool Prefix(ExtractionPoint __instance)
		{
			int extractionPointSurplus = RoundDirector.instance.extractionPointSurplus;
			if (extractionPointSurplus > 0)
			{
				if (SemiFunc.IsMasterClientOrSingleplayer())
				{
					if (extractionPointSurplus <= 13000)
					{
						SpawnBag(__instance, extractionPointSurplus, 0, 1, useCircleLayout: false);
					}
					else
					{
						List<int> list = DistributeValues(extractionPointSurplus);
						for (int i = 0; i < list.Count; i++)
						{
							SpawnBag(__instance, list[i], i, list.Count, useCircleLayout: true);
						}
					}
				}
				__instance.surplusLightActive = true;
				__instance.surplusLight.intensity = __instance.surplusLightIntensity;
				__instance.surplusLight.range = __instance.surplusLightRange;
			}
			RoundDirector.instance.extractionPointSurplus = 0;
			return false;
		}

		private static List<int> DistributeValues(int totalSurplus)
		{
			List<int> list = new List<int>();
			int num = Mathf.CeilToInt((float)totalSurplus / 10000f);
			int num2 = ((totalSurplus > 200000) ? 7 : 5);
			num = Mathf.Clamp(num, 2, num2);
			int num3 = Mathf.CeilToInt((float)totalSurplus / (float)num);
			int num4 = Mathf.Max(13000, Mathf.CeilToInt((float)num3 * 1.3f));
			bool flag = totalSurplus <= 200000;
			int num5 = totalSurplus;
			for (int i = 0; i < num; i++)
			{
				int num6 = num - i;
				if (num6 == 1)
				{
					list.Add(Mathf.Max(num5, 8000));
					break;
				}
				int num7 = num5 / num6;
				int num9;
				if (flag)
				{
					int num8 = Mathf.RoundToInt((float)num7 * Random.Range(-0.3f, 0.3f));
					num9 = num7 + num8;
				}
				else
				{
					num9 = num7;
				}
				int num10 = 8000;
				int num11 = Mathf.Min(num4, num5 - 8000 * (num6 - 1));
				num9 = Mathf.Clamp(num9, num10, num11);
				list.Add(num9);
				num5 -= num9;
			}
			return list;
		}

		private static void SpawnBag(ExtractionPoint instance, int value, int index, int totalBags, bool useCircleLayout)
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = ((value > 8000) ? AssetManager.instance.surplusValuableBig : ((value <= 3500) ? AssetManager.instance.surplusValuableSmall : AssetManager.instance.surplusValuableMedium));
			Vector3 val3;
			if (useCircleLayout)
			{
				float num = 0.55f + (float)totalBags * 0.05f;
				float num2 = (float)index / (float)totalBags * MathF.PI * 2f;
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(Mathf.Cos(num2) * num, 0f, Mathf.Sin(num2) * num);
				val3 = instance.surplusSpawnTransform.position + val2 + Vector3.up * ((float)index * 0.18f);
			}
			else
			{
				val3 = instance.surplusSpawnTransform.position;
			}
			GameObject val4 = (SemiFunc.IsMultiplayer() ? PhotonNetwork.InstantiateRoomObject("Valuables/" + ((Object)val).name, val3, Quaternion.identity, (byte)0, (object[])null) : Object.Instantiate<GameObject>(val, val3, Quaternion.identity));
			if (!((Object)(object)val4 == (Object)null))
			{
				ValuableObject component = val4.GetComponent<ValuableObject>();
				if ((Object)(object)component != (Object)null)
				{
					component.dollarValueOverride = value;
				}
				float num3 = ComputeScale(value);
				num3 = Mathf.Min(num3, 1.3f);
				val4.transform.localScale = new Vector3(num3, num3, num3);
				PhysGrabObject component2 = val4.GetComponent<PhysGrabObject>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.spawnTorque = Random.insideUnitSphere * 0.05f;
				}
			}
		}

		private static float ComputeScale(int value)
		{
			if ((float)value <= 2000f)
			{
				float num = Mathf.InverseLerp(150f, 2000f, (float)value);
				return Mathf.Lerp(0.25f, 0.55f, num);
			}
			if ((float)value <= 10000f)
			{
				float num2 = Mathf.InverseLerp(2000f, 10000f, (float)value);
				return Mathf.Lerp(0.55f, 1f, num2);
			}
			float num3 = Mathf.InverseLerp(10000f, 13000f, (float)value);
			return Mathf.Lerp(1f, 1.3f, num3);
		}
	}
}