Decompiled source of HaulerTweaks v0.1.0

REPOHaulerTweaks.dll

Decompiled 2 weeks 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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace REPOHaulerTweaks
{
	[BepInPlugin("justrat.repo.haulertweaks", "Hauler Tweaks", "0.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "justrat.repo.haulertweaks";

		public const string PluginName = "Hauler Tweaks";

		public const string PluginVersion = "0.2.0";

		internal static ManualLogSource Log;

		public static ConfigEntry<float> BoxValueLimit;

		public static ConfigEntry<Type> MaxAcceptedVolume;

		public static ConfigEntry<bool> DisableGenericImpactDurabilityLoss;

		private readonly Harmony _harmony = new Harmony("justrat.repo.haulertweaks");

		private void Awake()
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			BoxValueLimit = ((BaseUnityPlugin)this).Config.Bind<float>("Hauler.Box", "BoxValueLimit", 35000f, "Абсолютный лимит суммарной стоимости лута в боксе Hauler'а. Полностью заменяет значение из префаба.");
			MaxAcceptedVolume = ((BaseUnityPlugin)this).Config.Bind<Type>("Hauler.Box", "MaxAcceptedVolume", (Type)2, "Максимальный ValuableVolume.Type, который бокс Hauler'а считает подходящим по размеру. Ванильно это Small (то есть влезают только Tiny/Small). Порядок: Tiny < Small < Medium < Big < Wide < Tall < VeryTall. Если предмет физически крупнее модели бокса, он может визуально клипать сквозь неё.");
			DisableGenericImpactDurabilityLoss = ((BaseUnityPlugin)this).Config.Bind<bool>("Hauler.Durability", "DisableGenericImpactDurabilityLoss", true, "true = Hauler теряет прочность только от ударов о мобов (как Scout), а не от любых столкновений со стенами/объектами/землёй. false = ванильное поведение (теряет прочность от всего).");
			_harmony.PatchAll();
			Log.LogInfo((object)("Hauler Tweaks v0.2.0 loaded. " + $"BoxValueLimit={BoxValueLimit.Value}, MaxVolume={MaxAcceptedVolume.Value}, " + $"DisableGenericImpactDurabilityLoss={DisableGenericImpactDurabilityLoss.Value}"));
		}
	}
}
namespace REPOHaulerTweaks.Patches
{
	[HarmonyPatch(typeof(ItemValuableBox))]
	internal static class HaulerBoxPatches
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start_Postfix(ItemValuableBox __instance)
		{
			__instance.valueLimit = Plugin.BoxValueLimit.Value;
		}

		[HarmonyPatch("OnObjectsFound")]
		[HarmonyPrefix]
		private static bool OnObjectsFound_Prefix(ItemValuableBox __instance, List<PhysGrabObject> foundObjects)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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)
			Traverse val = Traverse.Create((object)__instance);
			List<PhysGrabObject> value = val.Field("validObjectsInBox").GetValue<List<PhysGrabObject>>();
			value.Clear();
			HashSet<PhysGrabObject> hashSet = new HashSet<PhysGrabObject>();
			HashSet<PhysGrabObject> hashSet2 = new HashSet<PhysGrabObject>();
			Type value2 = Plugin.MaxAcceptedVolume.Value;
			foreach (PhysGrabObject foundObject in foundObjects)
			{
				ValuableObject component = ((Component)foundObject).GetComponent<ValuableObject>();
				if (!Object.op_Implicit((Object)(object)component))
				{
					continue;
				}
				if (component.volumeType > value2)
				{
					hashSet.Add(foundObject);
					continue;
				}
				float value3 = Traverse.Create((object)component).Field("dollarValueCurrent").GetValue<float>();
				if (__instance.CurrentValue + value3 > __instance.valueLimit)
				{
					hashSet2.Add(foundObject);
				}
				value.Add(foundObject);
			}
			val.Field("tooBigOffenders").SetValue((object)hashSet);
			val.Field("tooFullOffenders").SetValue((object)hashSet2);
			val.Method("UpdateStickyMessage", Array.Empty<object>()).GetValue();
			if (value.Count > 0)
			{
				val.Method("UpdateTextScreen", Array.Empty<object>()).GetValue();
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(ItemVehicle))]
	internal static class HaulerDurabilityPatches
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start_Postfix(ItemVehicle __instance)
		{
			if (Plugin.DisableGenericImpactDurabilityLoss.Value && (Object)(object)__instance.valuableBox != (Object)null)
			{
				__instance.smallImpactDurabilityLoss = 0f;
				__instance.mediumImpactDurabilityLoss = 0f;
				__instance.bigImpactDurabilityLoss = 0f;
				Plugin.Log.LogInfo((object)("[HaulerTweaks] Отключил бытовой урон по прочности для Hauler'а (" + ((Object)__instance).name + ")."));
			}
		}
	}
}