Decompiled source of GraveGearFirst v2.0.0

GraveGearFirst.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
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: AssemblyCompany("GraveGearFirst")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GraveGearFirst")]
[assembly: AssemblyTitle("GraveGearFirst")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 GraveGearFirst
{
	[BepInPlugin("saru.gravegearfirst", "Grave Gear First", "2.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "saru.gravegearfirst";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<float> ExtraWeight;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Augmente la capacite de poids du joueur tant qu'une tombe est ouverte, pour que le Take All puisse tout reprendre.");
			ExtraWeight = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ExtraWeight", 5000f, "Poids supplementaire accorde pendant ce temps.");
			_harmony = new Harmony("saru.gravegearfirst");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal static class GraveState
	{
		private static readonly FieldInfo CurrentContainerField = AccessTools.Field(typeof(InventoryGui), "m_currentContainer");

		private static Container _cachedContainer;

		private static bool _cachedIsGrave;

		internal static bool Interacting;

		internal static bool GraveIsOpen()
		{
			if (Interacting)
			{
				return true;
			}
			if (CurrentContainerField == null)
			{
				return false;
			}
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			object? value = CurrentContainerField.GetValue(instance);
			Container val = (Container)((value is Container) ? value : null);
			if ((Object)(object)val == (Object)null)
			{
				_cachedContainer = null;
				return false;
			}
			if (val != _cachedContainer)
			{
				_cachedContainer = val;
				_cachedIsGrave = (Object)(object)((Component)val).GetComponent<TombStone>() != (Object)null;
				if (_cachedIsGrave)
				{
					Plugin.Log.LogInfo((object)$"Tombe ouverte : +{Plugin.ExtraWeight.Value:F0} de capacite.");
				}
			}
			return _cachedIsGrave;
		}
	}
	[HarmonyPatch(typeof(TombStone), "Interact")]
	internal static class TombStoneInteractPatch
	{
		private static void Prefix()
		{
			if (Plugin.Enabled.Value)
			{
				GraveState.Interacting = true;
			}
		}

		private static void Finalizer()
		{
			GraveState.Interacting = false;
		}
	}
	[HarmonyPatch(typeof(Player), "GetMaxCarryWeight")]
	internal static class MaxCarryWeightPatch
	{
		private static void Postfix(Player __instance, ref float __result)
		{
			if (Plugin.Enabled.Value && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && GraveState.GraveIsOpen())
			{
				__result += Plugin.ExtraWeight.Value;
			}
		}
	}
}