Decompiled source of DestructibleDrone v1.0.3

com.github.zehsteam.DestructibleDrone.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 REPOLib;
using REPOLib.Modules;
using UnityEngine;
using com.github.zehsteam.DestructibleDrone.Extensions;
using com.github.zehsteam.DestructibleDrone.MonoBehaviours;
using com.github.zehsteam.DestructibleDrone.Objects;
using com.github.zehsteam.DestructibleDrone.Patches;

[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: AssemblyCompany("Zehs")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("Copyright © 2025 Zehs")]
[assembly: AssemblyDescription("Adds a new drone that's the opposite of an indestructible drone. This drone gives a higher reward but at an even higher risk.")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+0bc8912a57554f11a76c6721930cfa1913687263")]
[assembly: AssemblyProduct("DestructibleDrone")]
[assembly: AssemblyTitle("com.github.zehsteam.DestructibleDrone")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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 com.github.zehsteam.DestructibleDrone
{
	internal static class ConfigManager
	{
		public static ConfigFile ConfigFile { get; private set; }

		public static ConfigEntry<bool> ExtendedLogging { get; private set; }

		public static ConfigEntry<float> ValueMultiplier { get; private set; }

		public static ConfigEntry<float> FragilityMultiplier { get; private set; }

		public static void Initialize(ConfigFile configFile)
		{
			ConfigFile = configFile;
			BindConfigs();
		}

		private static void BindConfigs()
		{
			ExtendedLogging = ConfigFile.Bind<bool>("General", "ExtendedLogging", false, "Enable extended logging.");
			ValueMultiplier = ConfigFile.Bind("Destructible Drone", "ValueMultiplier", 3f, "The value multiplier for destructible valuables.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f));
			FragilityMultiplier = ConfigFile.Bind("Destructible Drone", "FragilityMultiplier", 100f, "The fragility multiplier for destructible valuables.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 100f));
		}
	}
	internal static class Logger
	{
		public static ManualLogSource ManualLogSource { get; private set; }

		public static void Initialize(ManualLogSource manualLogSource)
		{
			ManualLogSource = manualLogSource;
		}

		public static void LogDebug(object data, bool extended = true)
		{
			Log((LogLevel)32, data, extended);
		}

		public static void LogInfo(object data, bool extended = false)
		{
			Log((LogLevel)16, data, extended);
		}

		public static void LogWarning(object data, bool extended = false)
		{
			Log((LogLevel)4, data, extended);
		}

		public static void LogError(object data, bool extended = false)
		{
			Log((LogLevel)2, data, extended);
		}

		public static void LogFatal(object data, bool extended = false)
		{
			Log((LogLevel)1, data, extended);
		}

		public static void Log(LogLevel logLevel, object data, bool extended = false)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (!extended || IsExtendedLoggingEnabled())
			{
				ManualLogSource manualLogSource = ManualLogSource;
				if (manualLogSource != null)
				{
					manualLogSource.Log(logLevel, data);
				}
			}
		}

		public static bool IsExtendedLoggingEnabled()
		{
			if (ConfigManager.ExtendedLogging == null)
			{
				return false;
			}
			return ConfigManager.ExtendedLogging.Value;
		}
	}
	[BepInPlugin("com.github.zehsteam.DestructibleDrone", "DestructibleDrone", "1.0.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("com.github.zehsteam.DestructibleDrone");

		internal static Plugin Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger.Initialize(Logger.CreateLogSource("com.github.zehsteam.DestructibleDrone"));
			Logger.LogInfo("DestructibleDrone has awoken!");
			_harmony.PatchAll(typeof(ValuableDirectorPatch));
			_harmony.PatchAll(typeof(PhysGrabObjectPatch));
			ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
			string text = Path.Combine(Utils.GetPluginDirectory(), "destructibledrone_assets");
			BundleLoader.LoadBundle(text, (Action<AssetBundle>)delegate(AssetBundle assetBundle)
			{
				if (TryLoadItem("Item Drone Destructible", assetBundle, out var item))
				{
					Items.RegisterItem(item);
				}
			}, false);
		}

		private Item LoadItem(string name, AssetBundle assetBundle)
		{
			if ((Object)(object)assetBundle == (Object)null)
			{
				Logger.LogError("Failed to load item \"" + name + "\". AssetBundle is null.");
				return null;
			}
			Item val = assetBundle.LoadAsset<Item>(name);
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError("Failed to load item \"" + name + "\". Item could not be found.");
				return null;
			}
			if ((Object)(object)val.prefab == (Object)null)
			{
				val.prefab = assetBundle.LoadAsset<GameObject>(name);
				if ((Object)(object)val.prefab == (Object)null)
				{
					Logger.LogError("Failed to load item \"" + name + "\". Item prefab could not be found.");
					return null;
				}
			}
			return val;
		}

		private bool TryLoadItem(string name, AssetBundle assetBundle, out Item item)
		{
			item = LoadItem(name, assetBundle);
			return (Object)(object)item != (Object)null;
		}
	}
	internal static class Utils
	{
		public static string GetPluginDirectory()
		{
			return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.github.zehsteam.DestructibleDrone";

		public const string PLUGIN_NAME = "DestructibleDrone";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}
namespace com.github.zehsteam.DestructibleDrone.Patches
{
	[HarmonyPatch(typeof(PhysGrabObject))]
	internal static class PhysGrabObjectPatch
	{
		[HarmonyPatch("OverrideTimersTick")]
		[HarmonyPostfix]
		private static void OverrideTimersTickPatch(PhysGrabObject __instance)
		{
			if (!__instance.IsDestructible())
			{
				ItemDroneDestructible.DecreasePhysGrabObjectValue(__instance);
			}
		}

		[HarmonyPatch("OverrideIndestructible")]
		[HarmonyPrefix]
		private static bool OverrideIndestructiblePatch(PhysGrabObject __instance)
		{
			if (__instance.IsDestructible())
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ValuableDirector))]
	internal static class ValuableDirectorPatch
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static void SetupHostPatch()
		{
			ItemDroneDestructible.ResetDestructibleDataList();
		}
	}
}
namespace com.github.zehsteam.DestructibleDrone.Objects
{
	public class DestructibleData
	{
		private float _currentValueMultiplier;

		public PhysGrabObject PhysGrabObject { get; private set; }

		public ValuableObject ValuableObject { get; private set; }

		public float TimeSinceDestructible { get; set; } = float.NegativeInfinity;


		public bool IsValueOverwritten { get; private set; } = false;


		public static float ValueMultiplier => GetValueMultiplier();

		public static float FragilityMultiplier => GetFragilityMultiplier();

		public DestructibleData(PhysGrabObject physGrabObject)
		{
			if (!((Object)(object)physGrabObject == (Object)null))
			{
				PhysGrabObject = physGrabObject;
				ValuableObject = ((Component)physGrabObject).GetComponent<ValuableObject>();
				_currentValueMultiplier = ValueMultiplier;
			}
		}

		public void UpdateTimeSinceDestructible()
		{
			TimeSinceDestructible = Time.realtimeSinceStartup;
		}

		public bool IsDestructible()
		{
			return Time.realtimeSinceStartup - TimeSinceDestructible <= 0.1f;
		}

		public void IncreaseValue()
		{
			if (!((Object)(object)ValuableObject == (Object)null) && SemiFunc.IsMasterClientOrSingleplayer() && !IsValueOverwritten)
			{
				IsValueOverwritten = true;
				_currentValueMultiplier = ValueMultiplier;
				float dollarValueCurrent = ValuableObject.dollarValueCurrent;
				dollarValueCurrent *= _currentValueMultiplier;
				ValuableObject.SetDollarValue(dollarValueCurrent);
			}
		}

		public void DecreaseValue()
		{
			if (!((Object)(object)ValuableObject == (Object)null) && SemiFunc.IsMasterClientOrSingleplayer() && IsValueOverwritten)
			{
				IsValueOverwritten = false;
				float dollarValueCurrent = ValuableObject.dollarValueCurrent;
				dollarValueCurrent /= _currentValueMultiplier;
				ValuableObject.SetDollarValue(dollarValueCurrent);
			}
		}

		private static float GetValueMultiplier()
		{
			if (ConfigManager.ValueMultiplier == null)
			{
				return 3f;
			}
			return ConfigManager.ValueMultiplier.Value;
		}

		private static float GetFragilityMultiplier()
		{
			if (ConfigManager.FragilityMultiplier == null)
			{
				return 100f;
			}
			return ConfigManager.FragilityMultiplier.Value;
		}
	}
}
namespace com.github.zehsteam.DestructibleDrone.MonoBehaviours
{
	public class ItemDroneDestructible : MonoBehaviour
	{
		private ItemDrone _itemDrone;

		private PhysGrabObject _myPhysGrabObject;

		private ItemEquippable _itemEquippable;

		private PhysGrabObject _previousMagnetTargetPhysGrabObject;

		public static Dictionary<PhysGrabObject, DestructibleData> DestructibleDataList { get; private set; } = new Dictionary<PhysGrabObject, DestructibleData>();


		private void Start()
		{
			_itemDrone = ((Component)this).GetComponent<ItemDrone>();
			_myPhysGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
			_itemEquippable = ((Component)this).GetComponent<ItemEquippable>();
		}

		private void Update()
		{
			if (!SemiFunc.IsMasterClientOrSingleplayer() || _itemEquippable.isEquipped || !_itemDrone.itemActivated)
			{
				return;
			}
			_myPhysGrabObject.OverrideZeroGravity(0.1f);
			_myPhysGrabObject.OverrideDrag(1f, 0.1f);
			_myPhysGrabObject.OverrideAngularDrag(10f, 0.1f);
			if (!_itemDrone.magnetActive)
			{
				return;
			}
			PhysGrabObject magnetTargetPhysGrabObject = _itemDrone.magnetTargetPhysGrabObject;
			if ((Object)(object)_previousMagnetTargetPhysGrabObject != (Object)(object)magnetTargetPhysGrabObject)
			{
				OnMagnetPhysGrabObject(magnetTargetPhysGrabObject);
				_previousMagnetTargetPhysGrabObject = magnetTargetPhysGrabObject;
			}
			if (!((Object)(object)magnetTargetPhysGrabObject == (Object)null) && !((Object)(object)magnetTargetPhysGrabObject.impactDetector == (Object)null))
			{
				if (SemiFunc.IsMasterClientOrSingleplayer() && magnetTargetPhysGrabObject.IsMassOrDragOverwritten())
				{
					_itemDrone.ForceTurnOff();
					_itemDrone.DeactivateMagnet();
				}
				else
				{
					SetDestructible(magnetTargetPhysGrabObject);
				}
			}
		}

		private void OnMagnetPhysGrabObject(PhysGrabObject physGrabObject)
		{
			if (!((Object)(object)physGrabObject == (Object)null) && !((Object)(object)physGrabObject.impactDetector == (Object)null) && SemiFunc.IsMasterClientOrSingleplayer() && !CanAttachDroneToObject(physGrabObject))
			{
				_itemDrone.ForceTurnOff();
				_itemDrone.DeactivateMagnet();
			}
		}

		private static bool CanAttachDroneToObject(PhysGrabObject physGrabObject)
		{
			if ((Object)(object)physGrabObject == (Object)null || (Object)(object)physGrabObject.impactDetector == (Object)null)
			{
				return false;
			}
			if (physGrabObject.impactDetector.inCart)
			{
				return false;
			}
			if (physGrabObject.grabbed)
			{
				return false;
			}
			if (physGrabObject.IsMassOrDragOverwritten())
			{
				return false;
			}
			SurplusValuable val = default(SurplusValuable);
			if (((Component)physGrabObject).TryGetComponent<SurplusValuable>(ref val))
			{
				return false;
			}
			return true;
		}

		public static void ResetDestructibleDataList()
		{
			DestructibleDataList.Clear();
		}

		public static void SetDestructible(PhysGrabObject physGrabObject)
		{
			if (!((Object)(object)physGrabObject == (Object)null) && TryGetOrCreateDestructibleData(physGrabObject, out var destructibleData))
			{
				destructibleData.UpdateTimeSinceDestructible();
				physGrabObject.OverrideFragility(DestructibleData.FragilityMultiplier);
				IncreasePhysGrabObjectValue(physGrabObject);
			}
		}

		public static void IncreasePhysGrabObjectValue(PhysGrabObject physGrabObject)
		{
			if (!((Object)(object)physGrabObject == (Object)null) && TryGetOrCreateDestructibleData(physGrabObject, out var destructibleData))
			{
				destructibleData.IncreaseValue();
			}
		}

		public static void DecreasePhysGrabObjectValue(PhysGrabObject physGrabObject)
		{
			if (!((Object)(object)physGrabObject == (Object)null) && TryGetOrCreateDestructibleData(physGrabObject, out var destructibleData))
			{
				destructibleData.DecreaseValue();
			}
		}

		public static bool TryGetDestructibleData(PhysGrabObject physGrabObject, out DestructibleData destructibleData)
		{
			if ((Object)(object)physGrabObject == (Object)null)
			{
				destructibleData = null;
				return false;
			}
			return DestructibleDataList.TryGetValue(physGrabObject, out destructibleData);
		}

		public static bool TryGetOrCreateDestructibleData(PhysGrabObject physGrabObject, out DestructibleData destructibleData)
		{
			if ((Object)(object)physGrabObject == (Object)null)
			{
				destructibleData = null;
				return false;
			}
			if (TryGetDestructibleData(physGrabObject, out destructibleData))
			{
				return true;
			}
			destructibleData = new DestructibleData(physGrabObject);
			DestructibleDataList[physGrabObject] = destructibleData;
			return true;
		}
	}
}
namespace com.github.zehsteam.DestructibleDrone.Extensions
{
	internal static class ConfigFileExtensions
	{
		public static ConfigEntry<T> Bind<T>(this ConfigFile configFile, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			return configFile.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, Array.Empty<object>()));
		}
	}
	public static class PhysGrabObjectExtensions
	{
		public static bool IsDestructible(this PhysGrabObject physGrabObject)
		{
			if ((Object)(object)physGrabObject == (Object)null)
			{
				return false;
			}
			if (!ItemDroneDestructible.TryGetDestructibleData(physGrabObject, out var destructibleData))
			{
				return false;
			}
			return destructibleData.IsDestructible();
		}

		public static bool IsMassOrDragOverwritten(this PhysGrabObject physGrabObject)
		{
			if ((Object)(object)physGrabObject == (Object)null)
			{
				return false;
			}
			if (physGrabObject.overrideMassGoDownTimer > 0f)
			{
				return true;
			}
			if (physGrabObject.overrideDragGoDownTimer > 0f)
			{
				return true;
			}
			return false;
		}
	}
	internal static class ValuableObjectExtensions
	{
		public static void SetDollarValue(this ValuableObject valuableObject, float value)
		{
			if (!((Object)(object)valuableObject == (Object)null) && SemiFunc.IsMasterClientOrSingleplayer())
			{
				if (SemiFunc.IsMultiplayer())
				{
					valuableObject.photonView.RPC("DollarValueSetRPC", (RpcTarget)0, new object[1] { value });
				}
				else
				{
					valuableObject.DollarValueSetRPC(value);
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}